matlab拟合出错:Function value and YDATA sizes are not equal.x=1:1:5;y=[1976882 2972166 3752790 4077716 4154964]';function y=fitline_1(a,x)y=a(1)+a(2)*x+a(3)*x.^2+a(4)*x.^3;a=lsqcurvefit('fitline_1',[1;1;1;1],x,y);请问哪里出现了问题?
来源:学生作业帮助网 编辑:六六作业网 时间:2025/01/03 06:43:16
matlab拟合出错:Function value and YDATA sizes are not equal.x=1:1:5;y=[1976882 2972166 3752790 4077716 4154964]';function y=fitline_1(a,x)y=a(1)+a(2)*x+a(3)*x.^2+a(4)*x.^3;a=lsqcurvefit('fitline_1',[1;1;1;1],x,y);请问哪里出现了问题?
matlab拟合出错:Function value and YDATA sizes are not equal.
x=1:1:5;
y=[1976882 2972166 3752790 4077716 4154964]';
function y=fitline_1(a,x)
y=a(1)+a(2)*x+a(3)*x.^2+a(4)*x.^3;
a=lsqcurvefit('fitline_1',[1;1;1;1],x,y);
请问哪里出现了问题?
matlab拟合出错:Function value and YDATA sizes are not equal.x=1:1:5;y=[1976882 2972166 3752790 4077716 4154964]';function y=fitline_1(a,x)y=a(1)+a(2)*x+a(3)*x.^2+a(4)*x.^3;a=lsqcurvefit('fitline_1',[1;1;1;1],x,y);请问哪里出现了问题?
把y赋值语句的转置符号去掉即可.
x是行向量,y应该也是行向量才对.
另外,使用多项式拟合完全可以用polyfit函数,比这个简单很多:
x=1:1:5;y=[1976882 2972166 3752790 4077716 4154964];
a=polyfit(x,y,3);
plot(x,y,'ro',x,polyval(a,x),'.-')