matlab拟合出错:Function value and YDATA sizes are not equal.
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/07 16:56:23
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);
请问哪里出现了问题?
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),'.-')
再问: 能帮忙直接写一下拟合完成的公式吗?其实我只想要一个公式
再答: 拟合公式:y = p1*x^3 + p2*x^2 + p3*x + p4
其中系数:
p1 = -2751.5
p2 = -1.3893e+05
p3 = 1.4634e+06
p4 = 6.4873e+05
y=[1976882 2972166 3752790 4077716 4154964];
a=polyfit(x,y,3);
plot(x,y,'ro',x,polyval(a,x),'.-')
![](http://img.wesiedu.com/upload/f/72/f7217f5066b68f49757dea169be1399c.jpg)
再问: 能帮忙直接写一下拟合完成的公式吗?其实我只想要一个公式
再答: 拟合公式:y = p1*x^3 + p2*x^2 + p3*x + p4
其中系数:
p1 = -2751.5
p2 = -1.3893e+05
p3 = 1.4634e+06
p4 = 6.4873e+05
Matlab Lsqucurvefit 函数 “Function value and YDATA sizes are n
matlab创建function出错,
matlab:Error:Function definitions are not permitted in this
matlab 出现Function definitions are not permitted at the promp
matlab的lsqcurvefit函数做幂函数拟合出错
关于matlab数据拟合曲线的问题,程序出错!
matlab中Error:Function definitions are not permitted at the p
在matlab中,Function definitions are not permitted at the promp
MATLAB高手求教 Error:Function definitions are not permitted at t
matlab报错Function definitions are not permitted at the prompt
matlab 不能运行 Function definitions are not permitted at the pr
matlab:出现错误Function definitions are not permitted in this co