MATLAB自定义函数拟合fit


   
   
   
   
  1. %自定义拟合函数f(t)=a* cos(k*t)* exp(w*t)
  2. clc,clear
  3. syms t
  4. x=[ 0; 0.4; 1.2; 2; 2.8; 3.6; 4.4; 5.2; 6; 7.2; 8; 9.2; 10.4; 11.6; 12.4; 13.6; 14.4; 15];%列向量
  5. y=[ 1; 0.85; 0.29; -0.27; -0.53; -0.4; -0.12; 0.17; 0.28; 0.15; -0.03; -0.15; -0.071; 0.059; 0.08; 0.032; -0.015; -0.02];
  6. f=fittype( 'a*cos(k*t)*exp(w*t)', 'independent', 't', 'coefficients',{ 'a', 'k', 'w'}); %fittype是自定义拟合函数
  7. cfun=fit(x,y,f) %根据自定义拟合函数f来拟合数据x,y
  8. xi= 0: 0.1: 20;
  9. yi=cfun(xi);
  10. plot(x,y, 'r*',xi,yi, 'b-');

 


结果:


cfun = 


     General model:
     cfun(t) = a*cos(k*t)*exp(w*t)
     Coefficients (with 95% confidence bounds):
       a =      0.9987  (0.9836, 1.014)
       k =       1.001  (0.9958, 1.006)
       w =     -0.2066  (-0.2131, -0.2002)



文章转自:https://blog.csdn.net/mlp750303040/article/details/77651124

你可能感兴趣的:(数模MATLAB)