|
|
|||||||||||||||
|
|
|||||||||||||||
|
6. Fitting non-polynomials #3 -
Complex functions |
|||||||||||||||
|
|
|||||||||||||||
|
For this problem you are to use the
data file lincrvcomph.mat. This is in
the previously mentioned zip file found on my classes webpage. |
|||||||||||||||
|
|
|||||||||||||||
|
a) Find the parameters ( a2,
a1, and a0) and the sum of squares (ss) and the sum of
squares per data point (ssdp) for the function:
|
|||||||||||||||
|
|
|||||||||||||||
|
|||||||||||||||
|
|
|||||||||||||||
|
b) Produce a plot showing the raw data
and the fitted curve. You should
produce a legend which places the data from the above table onto the plot in
a place that obscures the data and the plot as little as possible. |
|||||||||||||||
|
|
|||||||||||||||
|
|
|||||||||||||||
|
|
|||||||||||||||
|
%Program
to Solve Problem 6 for Linear Curve Fitting Homework %version
2007-10-05 D.W. Donovan clear all; load('lincrvcomph.mat','-ascii'); x=lincrvcomph(:,1); fx=lincrvcomph(:,2); g0=(x.^2-1); g1=(3*x.^3-5*x); g2=(x-4).^2; al00=g0'*g0; al01=g0'*g1; al02=g0'*g2; al10=al01; al11=g1'*g1; al12=g1'*g2; al20=al02; al21=al12; al22=g2'*g2; b0=fx'*g0; b1=fx'*g1; b2=fx'*g2; alpha3=[al00
al01 al02; al10 al11 al12; al20 al21 al22]; B3=[b0 b1
b2]'; A3=alpha3\B3; p3=A3(1)*g0+A3(2)*g1+A3(3)*g2; er3=p3-fx; ss3=er3'*er3; name='D.W.
Donovan'; tt31='Linear
Curve Fitting Homework Problem #6 using sums of functions'; tt32='g0 =
(x.^2-1), g1 = (3*x.^3-5*x), and g2 = (x-4).^2'; tt3=[tt31,' ',' \newline ',tt32,' \newline ',name,' ',date]; l3a0=['a0 = ',num2str(A3(1))]; l3a1=['a1 = ',num2str(A3(2))]; l3a2=['a2 = ',num2str(A3(3))]; l3ss=['sm Sq = ',num2str(ss3)]; l3ssdp=['sm Sq DP = ',num2str(ss3/size(fx,1))]; figure hold on; title(tt3); xlabel('x in unitless numbers') ylabel('f(x) in unitless numbers') plot(x,fx,'b*') plot(x,p3,'r') plot(max(x),min(fx),'w.') plot(max(x),min(fx),'w.') plot(max(x),min(fx),'w.') plot(max(x),min(fx),'w.') plot(max(x),min(fx),'w.') legend('raw data','fitted curve',l3a0,l3a1,l3a2,l3ss,l3ssdp,4); legend('boxoff') Sol={'a0 = ' A3(1); 'a1 = ' A3(2); 'a2 = ' A3(3); 'sm Sq = ' ss3; 'sm Sq DP = '
(ss3/size(fx,1))}; Sol %{ Sol = 'a0 = ' [
-34.9778] 'a1 = ' [ 7.1694] 'a2 = ' [
15.3815] 'sm Sq = '
[3.8437e+005] 'sm Sq DP = ' [5.2654e+003] %} |
|||||||||||||||
|
|||||||||||||||
|
|