马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
lsqcurvefit 拟合出错,怎么办呢?
m文件如下:
function y=curvefit123(beta,x)
D=beta(1);
L=beta(2);
Lg=beta(3);
h=beta(4);
tilt=beta(5);
y=1/8000000*D^3/tilt*(-2/(1-(-1+2*(x+Lg*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)^(1/2)/D)^2)^(1/2)*(-1+2*(x+Lg*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)^(1/2)/D)/(1+tilt^2)^(1/2)/D-2/(1+tilt^2)^(1/2)/D/(1-(-1+2*(x+Lg*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)^(1/2)/D)^2)^(1/2)*(1-2*(x+Lg*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)^(1/2)/D)+2*(pi-acos(-1+2*(x+Lg*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)^(1/2)/D))/(1+tilt^2)^(1/2)/D+2*(1-(-1+2*(x+Lg*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)^(1/2)/D)^2)^(1/2)*(-1+2*(x+Lg*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)^(1/2)/D)/(1+tilt^2)^(1/2)/D+2/(1-(-1+2*(x-(L-Lg)*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)^(1/2)/D)^2)^(1/2)*(-1+2*(x-(L-Lg)*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)^(1/2)/D)/(1+tilt^2)^(1/2)/D+2/(1+tilt^2)^(1/2)/D/(1-(-1+2*(x-(L-Lg)*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)^(1/2)/D)^2)^(1/2)*(1-2*(x-(L-Lg)*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)^(1/2)/D)-2*(pi-acos(-1+2*(x-(L-Lg)*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)^(1/2)/D))/(1+tilt^2)^(1/2)/D-2*(1-(-1+2*(x-(L-Lg)*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)^(1/2)/D)^2)^(1/2)*(-1+2*(x-(L-Lg)*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)^(1/2)/D)/(1+tilt^2)^(1/2)/D)+1/3000000*pi*h*(x+Lg*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)*(3-2*(x+Lg*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)^(1/2)/D)-1/3000000*pi*h*(x+Lg*tilt/(1+tilt^2)^(1/2))^2/(1+tilt^2)^(3/2)/D+1/3000000*pi*h*(x-(L-Lg)*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)*(3-2*(x-(L-Lg)*tilt/(1+tilt^2)^(1/2))/(1+tilt^2)^(1/2)/D)-1/3000000*pi*h*(x-(L-Lg)*tilt/(1+tilt^2)^(1/2))^2/(1+tilt^2)^(3/2)/D;
end
那个y是对一个式子求导数得到的,这么长我也不知道怎么处理?
命令行:
>> load 1.txt;
>> load 2.txt;
>> lsqcurvefit(curvefit123, [2529,3330,550,514,2.522522e-2], X1, X2);
出错信息:
??? Error using ==> lsqncommon at 101
LSQCURVEFIT cannot continue because user supplied objective function failed
with the following error:
Error using ==> mpower
Matrix must be square.
Error in ==> lsqcurvefit at 182
[x,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = ...
我想大概是点乘引起的 但是不知道怎么解决。
我换成不是向量的乘法...
n= length(x)
for k=i:n
...x(k)....
Function value and YDATA sizes are incommensurate.
也不行
谢谢大家啊 ,上面那个长式子似乎也不能化简呢
[ 本帖最后由 lando 于 2007-11-22 11:35 编辑 ] |