# s06 - Ma 449 Numerical Applied Mathematics Model Solutions...

This preview shows pages 1–4. Sign up to view the full content.

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Ma 449: Numerical Applied Mathematics Model Solutions to Homework Assignment 6 Prof. Wickerhauser Exercise 2(b) of Section 5.1, p.259. MATLAB CODE: <>x=[-6 -2 0 2 6]; y=[-5.3 -3.5 -1.7 0.2 4]; f=[-6 -2.84 -1.26 0.32 3.48]; <>one=[1 1 1 1 1]; n=5; <>xmean=one*x'/n XMEA = 0. <>ymean=one*y'/n YMEA = -1.2600 <>x-xmean*one ANS = -6. -2. 0. 2. 6. <>sxy = (x-xmean*one)*(y-ymean*one)' SXY = 63.2000 <>sx2 = (x-xmean*one)*(x-xmean*one)' SX2 = 80. <>a = sxy/sx2 A = .7900 <>b=ymean-a*xmean B = -1.2600 <>l=a*x+b*one L = -6.0000 -2.8400 -1.2600 .3200 3.4800 <>l-f ANS = 1.0E-15 * .0000 .0000 -.2220 -.3886 -.8882 <>l-y ANS = -.7000 .6600 .4400 .1200 -.5200 <>e2=(l-y)*(l-y)' E2 = .5299 Exercise 5 of Section 5.1, p.260. Let SX2, SX1, SY1, and SXY be the sums of x^2, x, y, and x*y, respectively, from Equation Eq. 10 of p.255. Then Eq. 10 can be written in matrix form as: / SX2 SX1 \ /A\ = /SXY\ \ SX1 N / \B/ \SY1/ This 2x2 system can be solved explicitly: /A\ = -1 / N -SX1 \ /SXY\ , \B/ D \ -SX1 SX2 / \SY1/ where D = SX2*N-SX1*SX1. Multiplying this out gives A = ( N*SXY - SX1*SY1)/D; B = (SX2*SY1 - SX1*SXY)/D Exercise 6 of Section 5.1, p.260. Let xm = SX1/N be the mean value of x(1),...,x(N). Then note that [x(k)-xm]*[x(k)-xm] = x(k)*x(k) - 2*xm*x(k) + xm*xm, so summing this over k=1,2,...,N gives Sum [x(k)-xm]*[x(k)-xm] = SX2 - 2*xm*SX1 + N*xm*xm k = SX2 - 2*SX1*SX1/N + SX1*SX1/N = SX2 - SX1*SX1/N = D/N This shows that D = N*Sum [x(k)-xm]*[x(k)-xm], k which is nonzero if x(1),...,x(N) contains at least 2 distinct points, since then [x(k)-xm] must be nonzero for some k. Algorithm 4(a,b,c) of Section 5.1, p.262. MATLAB CODE: OUTPUT: % generate the function: n=50; x=[1:n] * 0.1; y=x+cos(sqrt([1:n])); %(a) compute least-squares line y = ax+b: sx1=sum(x); sy1=sum(y); sx2=sum(x.*x); sxy=sum(x.*y); d=sx2*n-sx1*sx1; a=( n*sxy - sx1*sy1)/d A = 1.4186 b=(sx2*sy1 - sx1*sxy)/d B = -.8808 l=a*x+b*ones(x); %(b) compute the RMS error: e2=norm(l-y)/sqrt(n) E2 = .4032 %(c) plot the error: plot(l-y) * ** ** * * * * * * * * * * * * * * ** * * * * * ** ** ** * ** * * * ** ** * ** * * * * Exercise 2(c) of Section 5.2, p.275. MATLAB CODE: OUTPUT: x=[-2 -1 0 1 2]; y=[10 1 0 2 9]; n=5; % compute least-squares parabols y = ax^2+bx+c: sx1=sum(x); sx2=sum(x.*x); sx3=sum(x.*x.*x); sx4=sum(x.*x.*x.*x); sy1=sum(y); sxy=sum(x.*y); sxxy=sum(x.*x.*y); mx=[sx4 sx3 sx2 ; sx3 sx2 sx1 ; sx2 sx1 n]; rh=[sxxy sxy sy1]' ; coef=mx\rh; a=coef(1), A = 2.5000 b=coef(2), B = -.1000 c=coef(3), C = -.6000 p=a*x.*x+b*x+c*ones(x), P = 9.6000 2.0000 -.6000 1.8000 9.2000 y, Y = 10. 1. 0. 2. 9....
View Full Document

## This note was uploaded on 05/16/2010 for the course MATH 449 taught by Professor Wickerhauser during the Fall '09 term at Washington University in St. Louis.

### Page1 / 9

s06 - Ma 449 Numerical Applied Mathematics Model Solutions...

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

View Full Document
Ask a homework question - tutors are online