HW5 sol - ‘EQ‘ 5): 7p, m N N r: O '3 Z Z (A%X°1FT...

Info iconThis preview shows pages 1–2. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ‘EQ‘ 5): 7p, m N N r: O '3 Z Z (A%X°1FT é’fin-Xh Yfi)m>‘7 vai’hzr In) N93; ~§A ms: fl .fim) L§fl~ ' Y“ .. Z w P» :0 __ 2 2(‘107éi fig" fitnfivxof [(44:( ’9 W 7’“ 75$ “2| - N 2- C :C as; C “ X1?) F2 2) N Ca; 622 Problem 16 pag277 part(b). Least square fit to data using f(x)= A cos(x) + B sin(x). using the follow program one finds A: 0.499766928886434, and [email protected] - plot of‘this least quare fit to given data is also shown. ———————————————————————————— —wProgram———————~————~~————————~———~~——— x={ —3 "1.5 G 1.5_3]; y:[—0.1385 —2.1587 0.8330 2.2774 —0.5110]; C11=0; C12=0; C22=0; 01:0; D2=0; for n=1 5 C11=C11+(cos(x(n))) C22=C22%(sin(x(n)))“2; D1=Dl+cos(x( D2=D2+sin(x(n))*y(n); end; C:[C11 _C12; C12 C22]; D=[Dl 021'; Z: (inv(C))*D;‘ N=lOO;-d= (x(5)—x(1))/N; N1=N+1; for n=1:N1 xx(n)=x{1)+d*(n—1); yy(n)=Z(1)*cos(xx(n))+Z(2)*sin(xx(n)); end; . ‘ plot(x,y,'o',xx,yy,'k—') xlabe1(fx—axis') ylabel('y—axis') A2; C12=C12+cos(x(n *sin(x(n)); n)) )) *y(n); 3 O 2 1 o .9 fi 0» >1 —1 _2 a —3 —3 —2 -1 o 1 2 a To fine spline function for following data poiints: x(1)=—3; x(2)=e2; x(3)=l; x(4)=4; 7y(1)=2; y(2)=0: y(3)=3; y(4)=1: a We write the code for the problem from formulas in your book with s first term in equation (8) page 282 sign error corrected from — to + h0=x(2)#x(1); hl=x(3)wx{2); h2=x(4)—x(3); a0=h0; a1=h1; a2=h2; c0=a0;cl=a1:c2=a2; blm2*(h1+h0); b2=2*(h2+h1); 'd0=(Y(2)—y(1))/h0; d1=(y(3)"y(2))/h1; d2=(y(4)—y(3))/h2: .u1=6*(d1—d0); u2=6*(d2—d1); u={ul u21'; . '3c=[b1 c1; a1 b2}; ci=inv(c); mm=ci*u; m1=mm(1); m2=mm(2); % having found s"(x(n)), now we now find the spline function [email protected]; ' . nl=300; n2=300; n3=n0+n1+n2; dd=(X(4)—X(1))/n3; Np1=n0+1; 'for k=1:n@ 't=x(1)+dd*(k—1); .xc(k)=t; att=(m1/(6*h0))*(T—X(1))“3+(y(1)/h0)*(X(Z)—t); gyc(k)=tt+(y(2)/h0 —m1*hG/6)*(t—x(l)); end; Np2zn0+n1+l; gfor k=Npl:Np2' t=x(1)+dd*(kwl); xc(k)=t; tt=(m1/(6*h1))*(x(3)—t)“3+(m2/(6*h1))*(t—x(2))“3; yc(k)=tt+(y(2)/hl—m1*h1/6)*(x(3)—t)+(y(3)/h1—m2*hl/6)*(t—x(2)); end; ' Np3=n0+nl+n2+1; for k=Np2:Np3 ';t=x(1)+dd*(k—1); xc(k)=t; tt=(m2/(6*h2))*(x(4)—t)“3; yc(k)ztt+(y(3)/h2—m2*h2/6)*(x(4)et)+(y(4)/h2)*(t—x(3)); end; subplot(2,l,l) plot(x,y,'o',xc,yc) ‘ xlabel(’x—axis; solid line=spline function, 0 = data points') ylabel('y—axis') - f y—axis ~3 -2 -1 0 1 2 3 4 x—axis; solid line=spline function, 0 = data points 7 ...
View Full Document

This note was uploaded on 02/23/2012 for the course MATH 4301 taught by Professor Krwaw during the Fall '11 term at King Mongkut's Institute of Technology Ladkrabang.

Page1 / 2

HW5 sol - ‘EQ‘ 5): 7p, m N N r: O '3 Z Z (A%X°1FT...

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

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