Fitting to an intergral

3 vues (au cours des 30 derniers jours)
Jason Ngo
Jason Ngo le 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)
x0=(1,1)
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
@(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)
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.

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by