作业帮 > 综合 > 作业

Matlab Lsqucurvefit 函数 “Function value and YDATA sizes are n

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/13 04:20:14
Matlab Lsqucurvefit 函数 “Function value and YDATA sizes are not equal”
clear all;clc;
x=[35000 45000 55000];
y=[0.5646 0.7374 0.8743];
f=@(c,x)(c(2)*x.^c(3)*sin(pi/2*c(3))/(c(1)+c(2)*x.^c(3)*cos(pi/2*c(3))));
c0=[10000 10 0.01];
[c,resnorm]=lsqcurvefit(f,c0,x,y)
plot(x,y,'.-',x,f(c,x),'r:x')
legend('原始数据','拟合数据')
clear all;
clc;
x=[35000 45000 55000];
y=[0.5646 0.7374 0.8743];
f=@(c,x)(c(2)*x.^c(3)*sin(pi/2*c(3))./(c(1)+c(2)*x.^c(3)*cos(pi/2*c(3))));%注意这一行要用点除
c0=[10000 10 0.01];
[c,resnorm]=lsqcurvefit(f,c0,x,y)
plot(x,y,'.-',x,f(c,x),'r:x')
legend('原始数据','拟合数据')

结果:
Optimization terminated: first-order optimality less than OPTIONS.TolFun,
and no negative/zero curvature detected in trust region model.
c =
1.0e+003 *
10.0000 0.0300 0.0104
resnorm =
0.0482

点太少了