MTH510-A3-Solns

MTH510-A3-Solns - g: i 3 £65 QUAL ,, ,, , N. , 9 ) /...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: g: i 3 £65 QUAL ,, ,, , N. , 9 ) / >2 Cafl It 1,] g , , , ,, ,7 O 0 O 0 O 0 O 0.198466472303207 —0.22137l938775510 0.305347895408163 >> Jacobi(a,b,.05, x_l“i .2857142857 .1785714286 .2000000000 .1987244898 .1982653061 .1985076531 .1984664723 ans 2 50) x_2“i .2000000000 .2178571429 .2242857143 .2208928571 .2214693878 .2213915816 .2213719388 OOOOOOO x_3“i .3750000000 .3000000000 .3044642857 .3060714286 .3052232143 .3053673469 .3053478954 \ “eh ha‘méeénlaéaw 4 m m ¢ w M H H (ACE M%ékfzc:%;, ass: 17339541581 3% \l 7 / 37W; ace) Lea/0W1) Jacobi.m function x=Jacobi(A,b,es,maxit) if nargin<2, err0r(’at least 2 input arguments required’),end if nargin<4‘isempty(maxit),maxit=50;end if nargin<3fisempty(es),es=0.00001;end {m,n]:size(A); if m~=n, error(‘Matrix A must be square’);end C=A; for i=lzn C(i,i)=0; x(i)=0; end x=x’; x=[0; —O.5; O}; % New Line A3 Q 2c —‘« initial value for x for i=l:n C(i,l:n)=C(i,l:n)/A(i,i); end for i=lzn d(i)=b(i)/A(i,i); end iterzo; while (1) xold=x; for i=lzn % X(i):d{i)~C(i,:)*x; %Gauss Seidel x(i)=d(i)-C(i,:)*xold; % New line: Jacobi output(iter+l,i):x(i); % New Line A3 Q 2c ‘~~ for output if X(i) ~= O ea(i)=abs((x(i)—xold(i))/x(i))*100; end end iter=iter+l; x; % semi—colon added max(ea); % semi~colon added output(iter,4)=max(ea); % New line A3 Q 2c «—~ for output output(iter,5)=iter; % New line A3 Q 2c —A« for output if max(ea)<=es I iter >: maxit, break, end end iter; %semi—colon added fprintf(' x_lAi X 2Ai x 3“i e a 11’ \n’) _ fl “ fprintf(’%15.10f %15.10f %lS.lOf %10.2f %5d\n',output’); % New line A3 Q 2C1, «~~ for output l E 3 Wqu .Hozlwze f1 [8% mg . QZESLCQIOHQL o ;_ (-320! a 36133885681 .ooamao/ \ “Wm WWW” wmmwrwwfl, w w. WWWWWW,“ WNLZILgW3:1;giilfifiljgfihggifltfiiL) M;7”an§%ZLEiE§i£125212§§§6fiiKi§fi§fié§2‘ “WWWWM~w5113£flfifigfigwmmmwwmwwwmw w«wik ‘ “h 7 I r r w— WW 7, W, V » y: L » A, H , ,, ,éi&(%4\ +1 Mega) (WVMfl ,, ,, Q.,4H0 38%3 § so ’faywas MR +[Q.4§%338‘?83 x0 "aim mix/[é § LN, E‘s ~a3g5c.m x:[-4 0 1 6 8 ll]; y=[3 —1 O 12 20 40}; pl=polyfit(x,y.l) p2:polyfit(x,y,2) xleinspace(-4,ll)7 plot(xx,pl(2)+pl(l)*xx,xx,p2(3)+p2(2)*xx+p2(1)kx.“2) hold on P10t(x.y.’o'); 2.470338983050847 3.275423728813559 (TthxQQJK \ 0.314484456866569 0.224973263473862 —O.966118755111396 < 9 ‘ fx3 ‘ T T 03‘ ,,Ok( CED ‘ , Mm 5053.00] we may mmw : t‘ Gmepa @r QC) ...
View Full Document

Page1 / 12

MTH510-A3-Solns - g: i 3 £65 QUAL ,, ,, , N. , 9 ) /...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online