Fitting data with integral function

조회 수: 1 (최근 30일)
Daniel Suchet
Daniel Suchet 2017년 1월 19일
댓글: Walter Roberson 2017년 1월 20일
I want to fit an ensemble (t,Y) of data by a function defined as an integral
$$
f(x)=\int{\frac{A}{1+A*x*y}dy,0,10}
$$
where A is a parameter to be fitted on the data.
I tried something as follows
% t and y are previously defined as two array of numbers
syms z
f = @(x,xdata,z) x(1)/(1+x(1)*xdata*z);
fit = @(x,xdata) int(f(x,xdata,z),[0, 10]);
x0 = [1];
[x,resnorm,~,exitflag,output] = lsqcurvefit(fit,x0,t,y);
Unfortunately, the software available in my university is in Japanese, and I can't understand the error message. From my understanding, at least two things are problematic
  • I don't know if "int" can be used this way. For instance, I don't understand how to declare the variable on which the integral should be performed. I copied the MWE from https://fr.mathworks.com/help/symbolic/int.html
  • I don't know if "fit" can indeed be used as a fitting function.
Thank you for your help

답변 (1개)

Torsten
Torsten 2017년 1월 19일
편집: Torsten 2017년 1월 19일
Try
f = @(x,xdata,z) x(1)./(1+x(1)*xdata*z);
fit = @(x,xdata) integral(@(z)f(x,xdata,z),0,10,'ArrayValued',true);
x0 = 1;
[x,resnorm,~,exitflag,output] = lsqcurvefit(fit,x0,t,y);
Don't use z as symbolic variable now since you use integral instead of int.
Best wishes
Torsten.
  댓글 수: 2
Daniel Suchet
Daniel Suchet 2017년 1월 20일
Thank you for your answer.
I tried your proposal and received the following code (I found a way to get error messages in english eventually)
??? Undefined function or method 'integral' for input arguments of type
'function_handle'.
Error in ==> @(x,xdata)integral(@(z)f(x,xdata,z),0,10,'ArrayValued',true)
Error in ==> lsqcurvefit at 209
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in ==> NDRfit at 73
[x,resnorm,~,exitflag,output] = lsqcurvefit(fit,x0,y,t);
Caused by:
Failure in initial user-supplied objective function evaluation. LSQCURVEFIT cannot
continue.
Walter Roberson
Walter Roberson 2017년 1월 20일
It sounds as if you might be using a version before R2012a. For versions before that you should see quadgk() or quadl() or quad()

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

Community Treasure Hunt

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

Start Hunting!

Translated by