拟合 例 表 1 x 0 3 5 7 9 11 12 13 14 15 y 0 1.2 1.7 2.0 2.1 2.0 1.8 1.2 1.0 1.6 拟合求解函数表达式。
1 2 3 4 x=[0 3 5 7 9 11 12 13 14 15 ]; y=[0 1.2 1.7 2.0 2.1 2.0 1.8 1.2 1.0 1.6 ];plot (x,y)
1 2 3 4 5 6 7 8 9 10 x0=[0 3 5 7 9 11 12 13 14 15 ]'; y0=[0 1.2 1.7 2.0 2.1 2.0 1.8 1.2 1.0 1.6 ]';plot (x0,y0,'ro' );hold on [p1,s1]=polyfit(x0,y0,3 ) [y,delete]=polyval(p1,x0,s1)plot (x0,y) T = table (x0,y0,y,y0-y,'VariableNames' ,{'X' ,'Y' ,'Fit' ,'FitError' })
$$y=0.0012x^3-0.0517x^2+0.5939x-0.0541$$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 p1 = 0.0012 -0.0517 0.5939 -0.0541 s1 = 包含以下字段的 struct: R: [4 ×4 double] df: 6 normr: 0.6985 >> s1.Rans = 1.0e+03 * -5.4009 -0.3995 -0.0301 -0.0023 0 -0.0553 -0.0103 -0.0016 0 0 -0.0025 -0.0010 0 0 0 0.0010 delete = 0.3982 0.3397 0.3351 0.3216 0.3203 0.3236 0.3196 0.3143 0.3219 0.3701 T = 10 ×4 table X Y Fit FitError __ ___ _________ _________ 0 0 -0.054067 0.054067 3 1.2 1.2944 -0.094445 5 1.7 1.7716 -0.071558 7 2 1.9776 0.022391 9 2.1 1.9696 0.13044 11 2 1.8044 0.19564 12 1.8 1.6806 0.11936 13 1.2 1.539 -0.33899 14 1 1.3865 -0.38653 15 1.6 1.2304 0.36962
参考