MATLAB Answers

Fitting to an intergral

5 views (last 30 days)
Jason Ngo
Jason Ngo on 27 Mar 2020
Answered: Torsten on 27 Mar 2020
I am trying to fit a set of data to an integral with the following code but I get an error message. The parameters I am trying to obtain is x(1),x(2), and u, from xdata and ydata. Thanks.
fun= @(x, xdata) (1-((6*x(1))/(pi*sqrt(x(2)))))*integral(@(u) ((exp(-(xdata))*((u*cos(u)-sin(u))^2))/((u^2)*(((u^2)*(sin(u))^2)+(x(2))*(((x(1))/(x(2)))*(u*cos(u)-sin(u))+sin(u))^2))),0,Inf)
lsqcurvefit(fun, x0, xdata, ydata)
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix.
To perform elementwise multiplication, use '.*'.
Error in @(u)((exp(-(xdata))*((u*cos(u)-sin(u))^2))/((u^2)*(((u^2)*(sin(u))^2)+(x(2))*(((x(1))/(x(2)))*(u*cos(u)-sin(u))+sin(u))^2)))
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 83)
[q,errbnd] = vadapt(@AToInfInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in
Error in lsqcurvefit (line 213)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.


Sign in to comment.

Accepted Answer

Torsten on 27 Mar 2020
Use "ArrayValued=true" as option in the call to integral.


Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by