|
||||||||||||||||||
|
||||||||||||||||||
3. Non-Linear One Lorentzian
Function |
||||||||||||||||||
|
||||||||||||||||||
Use the
file “nlonelor.mat”, it contains data that should be fitted to a function of
the form: |
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
%Program
to solve non-linear Curve homework problem #3 %data
for a function F=a1/(a2^2+(x-a3)^2) %version
2015-09-30 D.W. Donovan clear all; load('nlonelor.mat','-ascii'); x=nlonelor(:,1); fx=nlonelor(:,2); figure hold on; t1b='Non-Linear
Curve Fitting Homework Problem #3'; t2b='Raw Data to
be Fitted to F(x) = a1/(a2^2+(x-a3)^2)'; name='D.W.
Donovan - '; tb=[t1b,'\newline',t2b,'\newline',name,date]; title(tb) xlabel('x in unitless numbers') ylabel('f(x) in unitless numbers') plot(x,fx) a00= [10000
-9 600]; a=fminsearch(@nlh3pf,a00); a1=a(1); a2=a(2); a3=a(3); ffx=a1./(a2.^2+(x-a3).^2); ss=(fx-ffx)'*(fx-ffx); xc=[min(x):(max(x)-min(x))/100:max(x)]'; fxc=a1./(a2.^2+(xc-a3).^2); la00=['a00 = ',num2str(a00)]; la1=['a1 = ',num2str(a1)]; la2=['a2 = ',num2str(a2)]; la3=['a3 = ',num2str(a3)]; lss=['sm Sq = ',num2str(ss)]; lssdp=['sm Sq DP = ',num2str(ss/size(fx,1))]; figure hold on; t1='Non-Linear
Curve Fitting Homework Problem #3'; t2='Data Fitted
to F(x) = a1/(a2^2+(x-a3)^2)'; t=[t1,'\newline',t2,'\newline',name,date]; title(t) xlabel('x in unitless numbers') ylabel('f(x) in unitless numbers') plot(x,fx,'r*') plot(xc,fxc,'b') plot(min(xc),max(fxc),'w') plot(min(xc),max(fxc),'w') plot(min(xc),max(fxc),'w') plot(min(xc),max(fxc),'w') plot(min(xc),max(fxc),'w') plot(min(xc),max(fxc),'w') legend('raw data','fitted curve',la00,la1,la2,la3,lss,lssdp,2); legend('boxoff') Sol={'parameter' 'Start' 'End'; 'a1 = ' a00(1) a1; 'a2 = ' a00(2) a2; 'a3 = ' a00(3) a3; 'sm Sq = ' 'n/a' ss ; 'sm Sq DP = ' 'n/a' (ss/size(fx,1))}; Sol %{ Sol = 'parameter' 'Start' 'End' 'a1 = ' [10000] [2.9856e+03] 'a2 = ' [
-9] [
7.9518] 'a3 = ' [
600] [ 450.0237] 'sm Sq = ' 'n/a' [ 301.2029] 'sm Sq DP = ' 'n/a' [ 2.9822] %} |
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
%Function
m-file needed to solve nonlinear Curve fitting homework #3 %version
2007-10-08 D.W. Donovan function f = fun(a) load('nlonelor.mat','-ascii'); x=nlonelor(:,1); fx=nlonelor(:,2); a1=a(1); a2=a(2); a3=a(3); g=a1./(a2.^2+(x-a3).^2); f=(g-fx)'*(g-fx); |
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
|