Combining fsolve and lsqcurvefit

2 次查看(过去 30 天)
Good evening,
I have a collection of experimental data (xi, yi) called (texp, rexp). I know that 'texp' must be derived from 'rexp' following:
t(i)=k(1)*integral(@(x) exp(-k(2)./(x.*log(x))), 1, r(i))
, being k(1) and k(2) parameters. So 'r(i)' is the upper integration limit. I need to find the values of k(1) and k(2) that best fits my model. My strategy is solving the equations 't(i)-texp=0' in 'r' with fsolve and fitting k(1) and k(2) with lsqcurvefit. I am trying this:
rteor=@(k,r) fsolve(@(r) arrayfun(@(T) k(1).*integral(@(x) exp(-k(2)./(x.*log(x))), 1, r)-T, texp), 1.0001);
x0=[2,6.12750];
k = lsqcurvefit(rteor, x0, texp, rexp)
which results on the following errors:
Error using lsqcurvefit (line 251)
Function value and YDATA sizes are not equal.
Thank you for your help!
  6 个评论
Walter Roberson
Walter Roberson 2018-6-6
You can get rid of the warning by passing an options structure to fsolve to tell it to use Levenberg-Marquardt
However, that suggests that multiple equations are attempted to be solved simultaneously, which is likely an error at some point.
Hmmm... notice that lsqcurvefit is going to be passing vectors to the function, so you need to expect that r will be a vector. When I answered you in https://www.mathworks.com/matlabcentral/answers/403892-fitting-data-to-integral-function#comment_574988 I was careful to use different variable names, R vs r, to make it clear whether one was receiving a vector or scalar at that point.
Sergio Quesada
Sergio Quesada 2018-6-7
编辑:Sergio Quesada 2018-6-7
well, taking your comment into account, I have made some advances. I changed the name of the variable in fsolve, with no effect. But i have changed the initial points to 8:
inpts=[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8];x0=[10 8];
rteor=@(k, r) arrayfun(@(p) fsolve(@(r) arrayfun(@(T) k(1).*integral(@(x) exp(-k(2)./(x.*log(x))), 1, r)-T, texp), p), inpts)
k = lsqcurvefit(rteor, x0, texp, rexp)
and matlab gives a result (after new 20-orange Levenberg-Marquardt warning messages):
k =
8.8155 9.8131
I am hopeful, but when trying to plot rteor with this values using
plot(texp,rexp,'ko',texp,rteor(k,texp),'x');
, 'rteor' appers as an horizontal line... Am i wrong now in 'plot' ?
(thanks !!!)

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by