How to fit integral function
Show older comments
Hi everyone, I have a function in two variables containing 5 parameters. I need to fit it to experimental data in order to find the values of parameters. The function is the following:

I have column vectors containing corresponding values of x, y and fun from experimental data.
The problem arises when i try to write the integral function:
%% fictitious experimental data
x=linspace(0,30,100);
y=linspace(0,50,100);
z=linspace(0,40,100);
% a=t(1)
% b=t(2)
% c=t(3)
% d=(4)
% e=t(5)
C=@(t) ((x - t(3))./t(1)).^2-2.*t(5).*((x - t(3))./t(1)).*((y - t(2))./t(4))+((y - t(2))./t(4)).^2;
k=@(t) 1./(t(1).*t(2)*sqrt(t(5))).*exp(-C(t)./t(5));
fun=@(t) integral2(k, 0, x, 0, y)-z;
t0=[1 1 1 1 1];
coeff = lsqnonlin(fun,t0);
What i get is
Error using integral2 (line 80)
XMAX must be a floating point scalar.
Does anyone know i can i express the integral in a better way and how to perform to the fitting phase?
Thank you in advance
Accepted Answer
More Answers (2)
Walter Roberson
on 6 Jul 2021
fun=@(t) integral2(k, 0, x, 0, y)-z;
Where are you using the input value, t ?
No, the t parameter will not be passed into k just because k happens to be a function whose dummy parameter name is the same as t.
Remember, this is integral2(), so the first parameter (k here) must evaluate to the handle of a function that accepts x and y values. For example,
fun = @(t) integral2(@(x,y)k(x,y,t), 0, x, 0, y) - z;
Also
x=linspace(0,30,100);
Your x is a vector, but you are trying to use that vector as the upper bound for integral2(). integral2() can only accept one scalar bound at a time.
If you want to fit at several x and y then you can break the overall x range into pieces, and the y range into pieces, and integrate over the rectangles, and cumsum() in two directions in order to get the grid.
Luca Guida
on 9 Jul 2021
0 votes
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!