imaginary value from solution nonlinier least square
显示 更早的评论
im trying to fitting data from reflectance measurement with lavenberg marquardt algorithm , ive got this code LMFnlsq in file exchange but i dont understand how to use it in my case
here is the equation
R = (0.6/(a + b))*(sqrt(3*a*(a + b))+(1/c))*(exp(-sqrt(3*a*(a + b ))*c))/(c^2)
a and b is parameter that im trying to solve
R is known vector from measurement reflectance
c is known vector from distance in measurement
im using the code like this
r = [0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.6]';
data = [0.787357544 0.63199586 0.393109753 0.271890049 0.179074593 0.133498607 0.112568249 0.05274273]';
res = @(x) ((0.6./(x(1)+x(2))).*(sqrt(3.*x(1).*(x(1)+x(2)))+(1./r)).* (exp(-sqrt(3*x(1).*(x(1)+x(2)))*r))./(r.^2)) - data;
x0 = [0.1,10];
[x,ssq,cnt] = LMFnlsq(res,x0)
hold on
plot(r,data)
plot(r,res(x)+ data,'y'), grid
the problem is it sure did the iteration but the final value is in imaginary solution like this
x =
0.0528 - 0.2730i
1.1469 + 0.6248i
ssq =
0.0091
cnt =
29
anything wrong with the code?
采纳的回答
更多回答(1 个)
Matt J
2013-2-28
0 个投票
You have square roots in your function, which will produce complex values when their argument goes negative. You must use another algorithm, one that lets you constrain 3*a*(a + b))+(1/c) to a strictly positive lower bound.
类别
在 帮助中心 和 File Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!