當前位置:編程學習大全網 - 源碼下載 - 如何用matlab進行多元非線性擬合

如何用matlab進行多元非線性擬合

matlab擬合工具箱cftool

%擬合數據曲線;線性最小二乘法是解決曲線擬合的最常用的方法,

%1、多項式擬合函數;p=polyfit(x,y,n);求p擬合函數在xi處的近似值pi=polyval(p,xi);

%2、利用常用矩陣的除法解決復雜函數的擬合;

%3、利用lsqcurvefit函數和lsqnonlin函數擬合;

%4、利用cftool工具箱,自定義編寫函數再通過M文件導出的形式

/doku.php?id=howtos:matlab:mt1-5

/zzz700/blog/item/f313a3f5869659b5a40f52d7.html英文參考

壹、 單壹變量的曲線逼近

Matlab有壹個功能強大的曲線擬合工具箱 cftool ,使用方便,能實現多種類型的線性、非線性曲線擬合。下面結合我使用的 Matlab R2007b 來簡單介紹如何使用這個工具箱。

假設我們要擬合的函數形式是 y=A*x*x + B*x, 且A>0,B>0。

1、在命令行輸入數據:

》x=[110.3323 148.7328 178.064 202.8258033 224.7105 244.5711 262.908 280.0447 296.204 311.5475];

》y=[5 10 15 20 25 30 35 40 45 50];

2、啟動曲線擬合工具箱

》cftool

3、進入曲線擬合工具箱界面“Curve Fitting tool”

(1)點擊“Data”按鈕,彈出“Data”窗口;

(2)利用X data和Y data的下拉菜單讀入數據x,y,可修改數據集名“Data set name”,然後點擊“Create data set”按鈕,退出“Data”窗口,返回工具箱界面,這時會自動畫出數據集的曲線圖;

(3)點擊“Fitting”按鈕,彈出“Fitting”窗口;

(4)點擊“New fit”按鈕,可修改擬合項目名稱“Fit name”,通過“Data set”下拉菜單選擇數據集,然後通過下拉菜單“Type of fit”選擇擬合曲線的類型,工具箱提供的擬合類型有:

Custom Equations:用戶自定義的函數類型

Exponential:指數逼近,有2種類型, a*exp(b*x) 、 a*exp(b*x) + c*exp(d*x)

Fourier:傅立葉逼近,有7種類型,基礎型是 a0 + a1*cos(x*w) + b1*sin(x*w)

Gaussian:高斯逼近,有8種類型,基礎型是 a1*exp(-((x-b1)/c1)^2)

Interpolant:插值逼近,有4種類型,linear、nearest neighbor、cubic spline、shape-preserving

Polynomial:多形式逼近,有9種類型,linear ~、quadratic ~、cubic ~、4-9th degree ~

Power:冪逼近,有2種類型,a*x^b 、a*x^b + c

Rational:有理數逼近,分子、分母***有的類型是linear ~、quadratic ~、cubic ~、4-5th degree ~;此外,分子還包括constant型

Smoothing Spline:平滑逼近(翻譯的不大恰當,不好意思)

Sum of Sin Functions:正弦曲線逼近,有8種類型,基礎型是 a1*sin(b1*x + c1)

Weibull:只有壹種,a*b*x^(b-1)*exp(-a*x^b)

選擇好所需的擬合曲線類型及其子類型,並進行相關設置:

——如果是非自定義的類型,根據實際需要點擊“Fit options”按鈕,設置擬合算法、修改待估計參數的上下限等參數;

——如果選Custom Equations,點擊“New”按鈕,彈出自定義函數等式窗口,有“Linear Equations線性等式”和“General Equations構造等式”兩種標簽。

在本例中選Custom Equations,點擊“New”按鈕,選擇“General Equations”標簽,輸入函數類型y=a*x*x + b*x,設置參數a、b的上下限,然後點擊OK。

(5)類型設置完成後,點擊“Apply”按鈕,就可以在Results框中得到擬合結果,如下例:

general model:

f(x) = a*x*x+b*x

Coefficients (with 95% confidence bounds):

a = 0.009194 (0.009019, 0.00937)

b = 1.78e-011 (fixed at bound)

Goodness of fit:

SSE: 6.146

R-square: 0.997

Adjusted R-square: 0.997

RMSE: 0.8263

同時,也會在工具箱窗口中顯示擬合曲線。

這樣,就完成壹次曲線擬合啦,十分方便快捷。當然,如果妳覺得擬合效果不好,還可以在“Fitting”窗口點擊“New fit”按鈕,按照步驟(4)~(5)進行壹次新的擬合。

不過,需要註意的是,cftool 工具箱只能進行單個變量的曲線擬合,即待擬合的公式中,變量只能有壹個。對於混合型的曲線,例如 y = a*x + b/x ,工具箱的擬合效果並不好。下壹篇文章我介紹幫同學做的壹個非線性函數的曲線擬合。

上邊對cftool工具箱做了很詳盡的說明,但並沒有對各種曲線擬合的性能做點評,在單變量曲線擬合中,如何選取壹種最優化的擬合方式是非常重要的,我們在采用CFTOOL擬合後,會有壹些性能說明,如:

Goodness of fit:

SSE: 6.146

R-square: 0.997

Adjusted R-square: 0.997

RMSE: 0.8263

官方的解釋:

Results -- Displays detailed results for the current fit including the fit type (model, spline, or interpolant), the fitted coefficients and 95% confidence bounds for parametric fits, and these goodness of fit statistics:

SSE -- The sum of squares due to error. This statistic measures the deviation of the responses from the fitted values of the responses. A value closer to 0 indicates a better fit.

R-square -- The coefficient of multiple determination. This statistic measures how successful the fit is in explaining the variation of the data. A value closer to 1 indicates a better fit.

Adjusted R-square -- The degree of freedom adjusted R-square. A value closer to 1 indicates a better fit. It is generally the best indicator of the fit quality when you add additional coefficients to your model.

RMSE -- The root mean squared error. A value closer to 0 indicates a better fit.

Matlab曲面擬合和插值 AAAAAAAAAAA風雲博客

/blog/#m=0&t=1&c=fks_084066080086083064084085083095087086083071083086086064

/blog/static/62173403201121095512602/?fromdm&fromSearch&isFromSearchEngine=yes

Matlab曲線擬合

/blog/static/30247003201153083539419/?fromdm&fromSearch&isFromSearchEngine=yes

多項式擬合函數polyfit之C語言的源碼

/blog/static/30247003201010251055758/

matlab二元函數擬合;

/question/141374449.html?fr=qrl&cid=93&index=2

matlab非線性擬合1(指數函數)

/share/detail/43922314

  • 上一篇:求教:魚內臟能否做肥料?
  • 下一篇:下雨天(短篇小說)
  • copyright 2024編程學習大全網