978-1107135116 Chapter 3 Part 1

subject Type Homework Help
subject Pages 14
subject Words 2267
subject Authors Kevin D. Dorfman, Prodromos Daoutidis

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Linear equations 105
5A = [6, 1; 4, -8];
6b = [13;0];
7x solve = A\b;
8
19 saveas(h,'s12c4p2 solution figure1.eps','psc2')
20
21 %make the zoom figure
22 small = 0.001;
23 axis([x solve(1)-small,x solve(1)+small,x solve(2)-small,...
34
35
36 function [x plot,y plot,err plot,k]=jacobi(A,x,b)
37 x old = x;
38 err = 100;
49 x plot(k) = x(1);
50 y plot(k) = x(2);
51 end
The output files are:
page-pf2
106 Linear equations
1.5 2 2.5 3 3.5 4 4.5 5
0
0.5
1
1.5
2
2.5
x
y
Solution t o s12c4p2
1.999 1.9992 1.9994 1.9996 1.9998 2 2.0002 2.0004 2.0006 2.0008 2.001
0.999
0.9992
0.9994
0.9996
0.9998
1
1.0002
1.0004
1.0006
1.0008
1.001
x
y
Solution to s12c 4p2
0.9996
0.9998
1
1.0002
1.0004
1.0006
1.0008
1.001
x
y
Solution to s12c 4p2
(2.82) The files for this problem are in the folder s10c2p1 matlab.
The Matlab script is:
page-pf3
Linear equations 107
1function s10c2p1
2close all
p and q = 0.
12 output(3,p) = size(find(A),1); %find the number of ...
non-zero elements
13 b = rand(n,1); %generate the forcing function
14 tic;
25 figure
26 plot(output(1,:),output(3,:),'o','MarkerSize',8)
27 xlabel('Value of p','FontSize',14)
28 ylabel('Number of non-zero elements in A','FontSize',14)
29 title('Solution to s10c2p1','FontSize',14)
of the matrix
40 j end = min(n,i+p);
41 for j = i:j end
42 A(i,j) = rand();
43 end
page-pf4
The output files are:
100101102103
10−3
10−2
10−1
Value f or p
T ime f or s ol ut ion ( s e c on ds )
Solution to s 10c2p1
100101102103
10−3
10−2
10−1
Value f or p
T ime f or s ol ut ion ( s e c on ds )
Solution to s 10c2p1
(2.83) The files for this problem are contained in the folder s12c4p3 matlab.
The Matlab script is:
1function s12c4p3
2clc
3close all
page-pf5
13 w = 0.1*z;
14 w plot(z) = w;
15 fprintf('\n*****************************************\n')
16 fprintf('\n\n Starting calculation for w = %3.1f \n',w)
17 k = 0;
28 end
29 r = (b(i) - s)/A(i,i);
30 x(i) = x(i) + w*r;
31 end
32 err = norm(A*x-b);
43 plot(w plot,n iter,'-ok')
44 xlabel('Relaxation parameter, $w$','FontSize',14),
45 ylabel('Solution to s12c4p3','FontSize',14)
46 saveas(h,'s12c4p3 solution figure.eps','psc2')
The output file is:
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
0
20
40
60
80
100
120
140
160
180
Re lax ation parame t er, w
Solution t o s12c4p3
page-pf6
110 Linear equations
(2.84) The files for this problem are contained in the folder s11c3p1 matlab.
The Matlab script is:
1function s11c3p1
2clc
3close all
14
15
16 for k = 1:npts
17 n=5*k;
18 n output(k) = n; %store the matrix size
29 end
30 b(i,1) = i*n;
31 end
32
33
44 end
page-pf7
Linear equations 111
45 end
46
47 if diag check >0
58 x = zeros(n,1);
59 iterations = 0;
60 err = 1000;
61
62 while err >tol
73 end
74
75
76 %check the solution
77 err = norm(A*x-b);
87 end
88 end
89 %save the number of iterations and the error
90 iter output(k) = iterations;
91 err output(k) = err;
page-pf8
101 title('Solution to s11c3p1','FontSize',14)
102 saveas(h,'s11c3p1 solution figure.eps','psc2')
103
104 %output the data in the correct format
105 write output(:,1) = n output;
page-pf9
Linear equations 113
23 115,0,8.6687e-09,47
24 120,0,5.9007e-09,51
(2.85) The files for this problem are contained in the folder s10c3p1 matlab.
The Matlab script for this problem is:
1function s10c3p1
2
3close all
14 epsilon out(i) = epsilon;%store epsilon
15 condition out(i) = cond(A);%compute the condition number
16 x=A\b;%solve the system
17 error out(i) = abs(epsilon*x(3) - 1);%compute the error. ...
the true value is 1/epsilon
28 xlabel('Condition Number','FontSize',14)
29 ylabel('Relative error in $x 3$','FontSize',14)
30 title('Solution to s10c3p1','FontSize',14)
page-pfa
114 Linear equations
31 saveas(h,'s10c3p1 solution figure2.eps','psc2')
10−15 10−10 10−5 100
102
104
106
108
1010
1012
1014
1016
1018
e p sil on
C ondit ion N umbe r
Solution t o s10c3p1
1021041061081010 1012 1014 1016 1018
10−16
10−14
10−12
10−10
10−8
10−6
10−4
10−2
100
C ondit ion N umbe r
Re lative e rror in x3
Solution t o s10c3p1
page-pfb
page-pfc
x(1) =223
(3.2) The general form of newtons method is
xk+1=xkf(xk)
(3.3) The general form of newtons method is
xk+1=xkf(xk)
x
(3.4) Newton’s method is
x(k+1) =x(k)f(x(k))
f(x(k))
For this problem, we have
page-pfd
(3.6) f=2xso the Newton’s method scheme is
x(k+1) =1
2x(k)
For nsteps of Newton’s method
(3.7) For Newton’s method, the derivative is
f=cos x(cos xxsin x)=xsin x
So we have
x(1)
n+1(x
n+π)+cos(x
n)
sin(x
n)
page-pfe
132 Nonlinear equations
(3.8) Find the solution of f(x)=exx(with initial guess x=1)
(3.9) Determining the function requires recognizing that log in Matlab is the natural log:
xln xx=0
x(ln x1) =0
The real roots are x=0 and x=e, so the largest real root is x=e=2.178.
(3.12) The result for quadratic convergence using a Taylor series is
|xk+1x|=
f′′(x(k))
2f(x(k))
(x(k)x)2
which we wrote as
f′′(x(k))
page-pff
(3.13) J="3x22y
y x #
(3.14)
x2x32x1x1x3+2x2x1x2
(3.15) (a) The steady state is the line x=0.
(b) The Jacobian is
J="y x
Jhx(1) x(0)i=R
For a linear system of equations, we have an initial residual
Jhx(1) x(0)i=hJx(0) bi
page-pf10
(3.17) The change in the unknowns on the first step is
δ=x(1) x(0) ="1
1#
The residual for step 0 is
R="4b+4
(3.18) For this initial guess, the residual is
R=
ǫ
ǫ
ǫ
The Jacobian is
x3+2x1x2x2
1x1+1
1 1 +ǫ1
page-pf11
1 1 5
1 1 +ǫ1
δ2
δ3
=
ǫ
ǫ
You only need to do the first step of Gauss elimination on the augmented matrix
1 (1 +ǫ)22+ǫǫ
1 1 5 ǫ
is consistent. In other words, assume that
δ=
ǫ
0
0
Then you need to show that
ǫ
ǫ
(3.19) Starting from the quadratic Taylor series approximation
f(x)f(x)+f(x)(xx)+f′′(x)(xx)2
if we let xbe close to the root then the RHS goes to zero and we can change the the
variables to match our iterative scheme
page-pf12
(3.20) The files for the problem are contained in the folder s10c4p2 matlab.
The exact solution is obtained by factoring x2(x1) =0, whereupon the roots are
x(3) =0.077
x(5) =0.0668
It takes k=91 iterations to get x<0.01 using this Matlab code:
x(1) =0.10.130.12
=0.0471
x(2) =0.0229
x(4) =0.0056
The scheme converges after 4 iterations.
The Matlab script is:
1function s10c4p2
2clc
page-pf13
12 disp(x) %print the first few values of x
13 end
14 end
15 disp('Total number of iterations')
16 disp(i)
(3.21) The files for this problem are contained in the folder s10c4p1 matlab.
The Matlab script is:
1function s10c4p1
2close all
3set(0,'defaulttextinterpreter','latex')
14 while abs(func(x)) >0.00001
15 x = x -func(x)/der(x);
16 end
17 root out(npts) = x; %record the root
18 npts = npts + 1; %update the counter for data output
page-pf14
28
29
30 function out = func(x)
31 out = sin(pi*x);
32
The three roots in our interval are x=0, 1 and 2. If the initial guess for Newton’s
(3.22) The files for this problem are in the folder s10c4p3 matlab.
The residual for the problem is
x3x2
zπsin[π(xz)] 2eyx
z2+πsin[π(xb)]

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.