matlab 拟合曲线u=a*i+b*i1+c*i2+d*i3+e*i4+f*i5;求abcdef的值,保证误差最小.u=[-190 -180 -170 -160 -150 -145 -140 -135 -130 -125 -120 -115 -110 -105 -100 -95 -90 -85 -80 0 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 160 170 180 1
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/26 13:14:21
matlab 拟合曲线u=a*i+b*i1+c*i2+d*i3+e*i4+f*i5;求abcdef的值,保证误差最小.u=[-190 -180 -170 -160 -150 -145 -140 -135 -130 -125 -120 -115 -110 -105 -100 -95 -90 -85 -80 0 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 160 170 180 1
matlab 拟合曲线u=a*i+b*i1+c*i2+d*i3+e*i4+f*i5;求abcdef的值,保证误差最小.
u=[-190 -180 -170 -160 -150 -145 -140 -135 -130 -125 -120 -115 -110 -105 -100 -95 -90 -85 -80 0 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 160 170 180 190];
i=[-11.75 -8 -5.4 -3.6 -2.55 -2.15 -1.78 -1.48 -1.24 -1.04 -0.84 -0.68 -0.54 -0.435 -0.35 -0.275 -0.225 -0.185 -0.155 0 0.155 0.185 0.225 0.275 0.35 0.435 0.54 0.68 0.84 1.04 1.24 1.48 1.78 2.15 2.55 3.6 5.4 8 11.75];
i1=[0 -14.5951 -8.70624 -5.05775 -3.15684 -2.6184 -2.03686 -1.57287 -1.21393 -0.92088 -0.61245 -0.38355 -0.18644 -0.05543 0.044303 0.132361 0.174174 0.204067 0.21981 0.509332 0.776095 0.766345 0.799222 0.859508 0.974783 1.107592 1.279786 1.520952 1.794451 2.143856 2.479135 2.892101 3.419236 4.075011 4.768147 6.829628 10.34208 15.33185 22.48945]
i2=[0 -25.8377 -13.0789 -6.01813 -2.83163 -2.39606 -1.58883 -0.95314 -0.48477 -0.11084 0.330913 0.616307 0.85861 0.978365 1.055434 1.126835 1.112922 1.092006 1.053912 1.612786 2.072008 1.92409 1.916399 1.977689 2.157985 2.366555 2.652525 3.074362 3.544815 4.16022 4.719022 5.432375 6.36428 7.532184 8.730749 12.81957 19.69495 29.26946 42.9261]
i3=[
0 -43.7625 -17.2727 -4.31146 0.439183 -0.14852 0.734815 1.423325 1.879181 2.232085 2.801955 3.062991 3.284045 3.279887 3.23269 3.209288 3.026973 2.864398 2.687172 3.805746 4.597123 4.064587 3.943544 3.985286 4.28014 4.613459 5.098447 5.85074 6.666365 7.760898 8.684832 9.924039 11.58369 13.67485 15.74084 23.92964 37.41955 55.7766 81.81628
]
i4=[
0 -69.0122 -16.5211 5.688279 11.26781 6.950073 7.329381 7.617703 7.657272 7.671443 8.285783 8.278246 8.28862 7.884205 7.479878 7.18926 6.595848 6.10784 5.622838 7.938698 9.300645 7.79536 7.42128 7.410709 7.928991 8.478009 9.32364 10.69434 12.11987 14.08715 15.59626 17.76465 20.74487 24.50981 28.05347 44.60122 71.11044 106.2533 155.8581
]
i5=[
0 -95.0329 3.074593 37.31438 39.53298 24.43079 22.78125 21.4573 20.05314 18.94978 19.36722 18.49246 17.85301 16.43822 15.19365 14.2947 12.79884 11.64078 10.5363 15.46346 17.78781 13.94605 13.08437 12.99184 13.98467 14.92531 16.44629 18.99726 21.50568 25.07885 27.49587 31.32388 36.72266 43.53728 49.56938 83.28256 135.4131 202.5398 296.9241
]
matlab 拟合曲线u=a*i+b*i1+c*i2+d*i3+e*i4+f*i5;求abcdef的值,保证误差最小.u=[-190 -180 -170 -160 -150 -145 -140 -135 -130 -125 -120 -115 -110 -105 -100 -95 -90 -85 -80 0 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 160 170 180 1
从下图的曲线可见,问题最大的症结在于:u在第20个点处有比较激烈的变化,而i,i1-i5都没有这样的变化的特征,所以想要使用这6个信号的先行叠加得到和u比较接近的值是不太现实的.
要想使拟合的总误差最小,可以用lsqcurvefit函数,代码如下(前面应该是你贴出来的数据定义,省略):
c0=ones(1,6);
c0=[16 -331 369 50 -153 39];
x=[i;i1;i2;i3;i4;i5];
f=inline('c(1)*x(1,:)+c(2)*x(2,:)+c(3)*x(3,:)+c(4)*x(4,:)+c(5)*x(5,:)+c(6)*x(6,:)','c','x');
opt=optimset('MaxFunEvals',1e5,'MaxIter',1e5);
c=lsqcurvefit(f,c0,x,u,[],[],opt) % 6个元素,分别对应a-f
plot(u,'o-')
hold on
plot(f(c,x),'x:r')
legend('原始数据','拟合数据',0)
得到的结果如下:
x = lsqr(A,u) attempts to solve the system of linear equations A*x=u for x if A is consistent, otherwise it attempts to solve the least squares solution x that
minimizes norm(b-A*x), x=(a,b,c,d,e,...
全部展开
x = lsqr(A,u) attempts to solve the system of linear equations A*x=u for x if A is consistent, otherwise it attempts to solve the least squares solution x that
minimizes norm(b-A*x), x=(a,b,c,d,e,f)
MATLAB
u=matrix(1,40,-190 -180 -170 -160 -150 -145 -140 -135 -130 -125 -120 -115 -110 -105 -100 -95 -90 -85 -80 0 80 85 90 95 100 105 110 115 120 125 130 135 140 145 150 160 170 180 190);
i=....,i1=...,..,i5=...
A=matrix(6,40,i,i1,i2,i3,i4,i5);
x = lsqr(A,u)
收起
遗传算法求方程系数,可以试试。