# Fitting to an intergral

조회 수: 3(최근 30일)
Jason Ngo 27 Mar 2020
답변: Torsten 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);
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 83)
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.

댓글을 달려면 로그인하십시오.

### 채택된 답변

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

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!

Translated by