5. Fitting non-polynomials #2 - Exponential functions

 

For this problem you are to use the data file lincrvexph.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:

 

 

 

 

 =

5.2757

 =

-3.3310

 

 =

2.9357

ss =

6.7579e+005

 

ssdp =

6.4361e+003

 

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 5 for Linear Curve Fitting Homework

%version 2007-10-05 D.W. Donovan

clear all;

load('lincrvexph.mat','-ascii');

x=lincrvexph(:,1);

fx=lincrvexph(:,2);

 

g0=exp(2*x);

g1=exp(6*x);

g2=exp(-4*x);

 

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 #5 using sums of Exp functions';

tt32='g0 = exp(2*x), g1 = exp(6*x), and g2 = exp(-4*x)';

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,3);

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 = '          [     2.9357]

    'a1 = '          [    -3.3310]

    'a2 = '          [     5.2757]

    'sm Sq = '       [6.7579e+005]

    'sm Sq DP = '    [6.4361e+003]

%}

 

Back To Dr. Donovan's Courses Page

 

Back To Dr. Donovan's Homepage

 

Physics Dept. Homepage

 

NMU Homepage

 

Please send any comments or questions about this page to ddonovan@nmu.edu

This page last updated on October 9, 2015