|
|
||||||||||||||||||
|
1. Non-Linear Exponential Function |
||||||||||||||||||
|
|
||||||||||||||||||
|
Use the file “nlexp.mat”, it contains
data that should be fitted to a function of the form:
|
||||||||||||||||||
|
|
||||||||||||||||||
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
|
%Program
to solve non-linear Curve homework problem #1 %data
for a function F=a1(e^(a2x)-a3) %version
2015-09-30 D.W. Donovan clear all; load('nlexp.mat','-ascii'); x=nlexp(:,1); fx=nlexp(:,2); figure hold on; t1b='Non-Linear
Curve Fitting Homework Problem #1'; t2b='Raw Data to
be Fitted to F(x) = a1[exp(a2x)-a3]'; 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= [15
1 -2] a=fminsearch(@nlh1pf,a00) a1=a(1); a2=a(2); a3=a(3); ffx=a1*(exp(a2*x)-a3); ss=(fx-ffx)'*(fx-ffx); xc=[min(x):(max(x)-min(x))/100:max(x)]'; fxc=a1*(exp(a2*xc)-a3); 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 #1'; t2='Data Fitted
to F(x) = a1[exp(a2x)-a3]'; 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 = ' [
15] [ 11.0647] 'a2 = ' [
1] [ 0.4889] 'a3 = ' [
-2] [ 3.1811] 'sm Sq = ' 'n/a'
[4.5789e+04] 'sm Sq DP = ' 'n/a' [
227.8063] %} |
||||||||||||||||||
|
|
||||||||||||||||||
|
%Function
m-file needed to solve nonlinear Curve fitting homework #1 %version
2007-10-08 D.W. Donovan function f = fun(a) load('nlexp.mat','-ascii'); x=nlexp(:,1); fx=nlexp(:,2); a1=a(1); a2=a(2); a3=a(3); g=a1*(exp(a2*x)-a3); f=(g-fx)'*(g-fx); |
||||||||||||||||||
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|