clc,clear
%定義一個符號變量t
syms t
%寫入要擬合數據
x=[0;1;3;10;30;100;300;1000;3000;5000;7000;10000];
y=[0;0.003915;-0.01044;-0.01184;-0.03737;-0.14699;-0.41946;-1.00311;-1.94593;-2.56821;-3.07218;-3.65212];
%編輯要擬合的公式,設置變量,設置系數
ft=fittype('a(1-exp(-(t/tau)^beta))','independent','t','coefficients',{'a','tau','beta'});
options = fitoptions(ft);
options.StartPoint=[1 10 1];
%設定擬合所用系數的上下限
options.Lower = [-999999 -99999 0];
options.Upper=[100 99999 1];
%進行擬合
cfun=fit(x,y,ft,options)
%顯示擬合函數,數據必須為列向量形式
xi=0:10:10000;
yi=cfun(xi);
figure
plot(x',y','r',xi,yi,'b-');
title('擬合函數圖形');
得到的擬合參數:
cfun =
General model:
cfun(t) = a*(1-exp(-(t/tau)^beta))
Coefficients (with 95% confidence bounds):
a = -5.807 (-6.909, -4.705)
tau = 1.021e+04 (5945, 1.448e+04)
beta = 0.7357 (0.6822, 0.7892)
擬合效果圖: