大家好,又見面了,我是你們的朋友全棧君。
1 函數指令拟合
最常用的函數拟合指令為fit,文法為|
[拟合結果 拟合精度]=fit(X資料,Y資料,‘拟合類型’)
其中,具體的拟合類型可以參看幫助文檔,也可以使用fittype來自定義新的函數類型,比如定義拟合函數
a*x+b*x^2+exp(4*x);
|
newtype=fittype('a*x+b*x^2+exp(4*x)') ;
fit(x,y,newtype);
x=[1;2;3;4;5];
y=[2;3;4;5;6];
複制
2 使用界面啟動拟合工具箱
具體操作步驟
- 在APP一欄,選擇
工具箱,然後選擇相應階段的資料,填入curve fitting
和X data
Y data
- 在
一欄選擇對應的函數形式,階數,和魯棒性fit options
- 點選工具欄的
,便于觀察拟合誤差residuals plot
- 點選工具欄的
,可以用滑鼠在曲線上标記出具體的坐标值data cursor
3 界面介紹
- 頂部為常用工具欄,常用的一般有誤差分析和滑鼠标記坐标點
-
可以選擇拟合類型和函數次數Fit Options
- 左側Results顯示了拟合結果的性能參數
- 底部的
可以對多個不同的拟合結果進行性能比較table of fits
4 拟合類型
拟合類型 | 解釋 |
---|---|
Custom Equations | 使用者自定義的函數類型 |
Exponential | exp指數逼近,有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) |
5 拟合結果說明
例如在上面的拟合中,選擇
Polynomial
類型,Degree選擇3階,Robust選擇Off,得到的Results如下:
Linear model Poly3:
f(x) = p1*x^3 + p2*x^2 + p3*x + p4
Coefficients (with 95% confidence bounds):
p1 = 0.0007776 (0.0007486, 0.0008066)
p2 = -0.121 (-0.1258, -0.1161)
p3 = 6.324 (6.055, 6.592)
p4 = -107 (-111.9, -102)
Goodness of fit:
SSE: 0.555
R-square: 0.9973
Adjusted R-square: 0.9973
RMSE: 0.03777
複制
其中,
Goodness of fit
裡面的性能名額如圖所示:
性能名額 | 解釋 |
---|---|
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. |
6 參考文獻
-
函數拟合工具包 [Fudan Physics Teaching Lab]
http://phylab.fudan.edu.cn/doku.php?id=howtos:matlab:mt1-5
-
Matlab的曲線拟合工具箱CFtool使用簡介 – yousun – 部落格園
https://www.cnblogs.com/yousun/p/3450676.html
釋出者:全棧程式員棧長,轉載請注明出處:https://javaforall.cn/160795.html原文連結:https://javaforall.cn