Re: Fitting function involving an integral



Randy Poe <poespam-trap@xxxxxxxxx> wrote in message
<1190992767.039335.288640@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>...
On Sep 28, 10:27 am, "Raffaello Ferone"
<raffaello.ferone.nos...@xxxxxxxxxxxxx> wrote:
Hello

I have a problem in fitting data with a
function involving an integral.
The function I have is:

G(exdata)=INTEGRAL[((f(1)./0.296).*(((f(3).^2)./(((x+f(4).*exdata(i)-f(2)).^2)+((f(3)).^2))).*((sech((1./(2*0.296)).*x)).^2)))
dx]

where f(i)s are the fitting parameters, x is the variable I
want to integrate over. exdata contains my experimental
data.
I defined in an m-file the function in the following way:

function y=fitfunction(f,exdata)
for i=1:length(exdata)

t(i)=quad(@(x)((f(1)./0.296).*(((f(3).^2)./(((x+f(4).*exdata(i)-f(2)).^2)+((f(3)).^2))).*((sech((1./(2*0.296)).*x)).^2))),-15,15,1.0e-10);
y=t';
end

I stress that I wrote exdata(i) and t(i) because exdata is a
vector of several points, and Matlab needs a scalar to
perform the integral. In this way, it performs the integral
for each value of exdata. In this way, the vector y is
built.
Then I use the previous function to fit my data by means of
the command: lsqcurvefit(@fitfunctionLorentzian, x0, xdata,
ydata,[],[],options) which appears in an another m-file.

The problem is that when I try to perform the fit, the value
I get for the fitting parameters are completely meaningless.
The experimental data represent a peak, and the Matlab for
some reason is not able at all to recognize even the center
of the peak.

This sounds familiar, like the variables are diverging far
away from where you think they should be, and the fit
function is essentially flat and unchanging (hence the
gradient
is near zero and the procedure exits). I've seen this, but I
can't recall what I did about it. Sorry.

And not even the order of magnitude. I do not
know whether I make some mistakes or not. Generally, I got
very good results for the fits thanks to Matlab.
Could someone help me, please?
Thanks a lot for your help.
Raffaello

If you plot fitfunction( x0, xdata ), does it look
reasonable? That
would be a check as to whether your function is doing what
you expect it to, and that x0 is reasonable.

Perhaps you could try using the bound constraints that
LSQCURVEFIT allows.

You might also try fixing some of your parameters
and only optimizing a subset.

- Randy



Hi Randy

When I plot fitfunction( x0, xdata ), where I suppose
that for you x0 is the vector with the values of the fitting
parameters, I get something which is very similar I expect
for, that is more or less a Lorentzian. This is in principle
quite good. But as I said, the position of the resulting
curve and the value of the different points are completely
inconsistent with the center of the peak represented by my
real experimental points. Concerning the values, there can
be even 2 order of magnitude of difference.
I really hope to find an explanation for all that. Is the
way I defined the function uncorrect, or there is a problem
in Matlab?
Thanks for any suggestion.
Raf
.



Relevant Pages

  • Re: 3d contour and surface plots from z,y and z data
    ... Fitting Toolbox 2.0 which ships with the 9a release of MATLAB. ... Lets assume that I have three 200 x 1 vectors named BSFC, SPEED, and LOAD ... I can create a fit object named Surface using the following command ...
    (comp.soft-sys.matlab)
  • Re: Fitting function involving an integral
    ... where fs are the fitting parameters, ... and Matlab needs a scalar to ... The problem is that when I try to perform the fit, ... some reason is not able at all to recognize even the center ...
    (comp.soft-sys.matlab)
  • Re: Fitting in Matlab
    ... The student version comes without the Curve Fitting Toolbox. ... Matlab is really wonderful for manipulating data (recorded in physical ...
    (comp.soft-sys.matlab)
  • Re: linear regression in 3D data points
    ... Why not to solve the fitting in two of the three possible pair of ... > I've imagined using a linear regression of matlab but without success ...
    (sci.image.processing)
  • help in single exponential fitting
    ... I am kind new in using Matlab. ... I used 'fit', however the fitting result is not good. ... Can anybody recommend a fitting function or method that is good in ...
    (comp.soft-sys.matlab)