matlab 非線性曲線擬合


%
matlab 非線性曲線擬合, nlinfit & lsqcurvefit & lsqnonlin;
%x0 初始向量
%p 表達式參數變量
xdata = [0.25 0.5 0.75 1 1.5 2 2.5 3 3.5 4 4.5 5 6 7 8 9 10 11 12 13 14 15 16];
ydata = [30 68 75 82 82 77 68 68 58 51 50 41 38 35 28 25 18 15 12 10 7 7 4];
figure(1);plot(xdata,ydata,'o');


%%
%(2):
f=inline('函數表達式','p','xdata');%內聯函數
p=nlinfit(xdata,ydata,f,x0);
%(3)
p=lsqcurvefit(f, x0, xdata, ydata)
%(4)
p= lsqnonlin(f, x0)
%%
%(1):
f1=inline('p1(1)*(exp(-p1(2)*xdata)-exp(-p1(3)*xdata))','p1','xdata');
x0=[114 0.18 2.01];
p1=nlinfit(xdata,ydata,f1,x0);
figure(1);hold on;plot(xdata,p1(1)*(exp(-p1(2)*xdata)-exp(-p1(3)*xdata)),'r');
%%(1):
p2=lsqcurvefit(f1,x0, xdata, ydata) ;
figure(1);hold on;plot(xdata,p2(1)*(exp(-p2(2)*xdata)-exp(-p2(3)*xdata)),'g')
%%(2):
p3=lsqnonlin(f,x0) ;
figure(1);hold on;plot(xdata,p3(1)*(exp(-p3(2)*xdata)-exp(-p3(3)*xdata)),'m')

%總結,效果基本一致;inlinfit對初值很敏感

參考:http://blog.sina.com.cn/s/blog_6ef450c80101gi2s.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM