Section 8.1 Problem 6 (a) >> x=[.2 .3 .6 .9 1.1 1.3 1.4 1.6]' x = 0.2000 0.3000 0.6000 0.9000 1.1000 1.3000 1.4000 1.6000 >> y=[.050446 .098426 .33277 .72660 1.0972 1.5697 1.8487 2.5015]' y = 0.0504 0.0984 0.3328 0.7266 1.0972 1.5697 1.8487 2.5015 >> A=[x ones(8,1)] A = 0.2000 1.0000 0.3000 1.0000 0.6000 1.0000 0.9000 1.0000 1.1000 1.0000 1.3000 1.0000 1.4000 1.0000 1.6000 1.0000 >> sol=inv(A'*A)*(A'*y) sol = 1.6655 -0.5125 Now, you can create a function file (linear.m) that holds the linear function y = ax+b: function v=linear(x) v=1.6655*x-0.5125; And you can plot the discrete (given) data and the continuous linear fitting by doing: >> x_cont=linspace(0.2,1.6,100); >> y_cont=linear(x_cont); >> plot(x,y,'x',x_cont,y_cont,'k') >> axis([0 1.7 -.5 2.6]) >> title('exponential fitting (-) of given data (x)'); (d) >> lny=log(y) lny = -2.9869 -2.3185 -1.1003 -0.3194 0.0928 0.4509 0.6145 0.9169 same A as in (a) >> sol=inv(A'*A)*(A'*lny) sol = 2.7073 -3.0855 >> a=sol(1) a = 2.7073 >> b=exp(sol(2)) b = 0.0457 Now, you can create a function file (exponential.m) that holds the linear function y = be^(ax): function v=exponential(x) v=0.0457*exp(2.7073*x); And you can plot the discrete (given) data and the continuous exponential fitting by doing: >> x_cont=linspace(0.2,1.6,100); >> y_cont=exponential(x_cont); >> plot(x,y,'x',x_cont,y_cont,'k') >> axis([0 1.7 -.5 2.6]) >> title('exponential fitting (-) of given data (x)'); (e) CORRECTED (1) polynomial fitting y=b*x^a >> lnx=log(x) lnx = -1.6094 -1.2040 -0.5108 -0.1054 0.0953 0.2624 0.3365 0.4700 >> A=[lnx ones(8,1)] A = -1.6094 1.0000 -1.2040 1.0000 -0.5108 1.0000 -0.1054 1.0000 0.0953 1.0000 0.2624 1.0000 0.3365 1.0000 0.4700 1.0000 >> sol=inv(A'*A)*(A'*lny) sol = 1.8720 -0.0511 >> b=exp(sol(2)) b = 0.9502 Now, you can create a function file (pol.m) that holds the polynomial function y = b*x^a: function v=pol(x) v=.9502*x^1.8720; And you can plot the discrete (given) data and the continuous polynomial fitting by doing: >> x_cont=linspace(0.2,1.6,100); >> for i=1:100, y_cont(i)=pol(x_cont(i)); end >> plot(x,y,'x',x_cont,y_cont,'k') >> axis([0 1.7 -.5 2.6]) >> title('polynomial fitting y = b*x^a (-) of given data (x)'); (2) Exponential fitting y=b*a^x: Matrix A same as in parts (a) and (d). >> sol=inv(A'*A)*(A'*lny) sol = 2.7073 -3.0855 >> a=exp(sol(1)) a = 14.9887 >> b=exp(sol(2)) b = 0.0457 >> for i=1:100, y_cont(i)=expon(x_cont(i)); end >> plot(x,y,'x',x_cont,y_cont,'k') Now, you can create a function file (expon.m) that holds the exponential function y = ba^x: function v=expon(x) v=.0457*(14.9887)^x; And you can plot the discrete (given) data and the continuous exponential fitting by doing: >> x_cont=linspace(0.2,1.6,100); >> for i=1:100, y_cont(i)=expon(x_cont(i)); end >> plot(x,y,'x',x_cont,y_cont,'k') >> axis([0 1.7 -.5 2.6]) >> title('exponential fitting y = b*a^x (-) of given data (x)');