insert two criteria function to lsqcurvefit

4 visualizaciones (últimos 30 días)
Mani Ahmadian
Mani Ahmadian el 26 de Nov. de 2014
Comentada: Star Strider el 29 de Dic. de 2014
Hi, I have some data points as (X,Y) and I want to use lsqcurvefit function to find the best fit by least square method. My guidance function is a non-linear function Gamma2(h) as bellow:
As above equation shows, it's a two criteria function and because the value of a0 is not clearly known, I have to use lsqcurvefit function simultaneously to reach the a0, but I don't know how to do it.
Please help me to solve problem.
Thanks, Mani

Respuestas (2)

Star Strider
Star Strider el 26 de Nov. de 2014
This works with simulated data:
% PARAMETERS: b(1) = C0, b(2) = a0
gamma2 = @(b,h) b(1).*[(1.5*(h/b(2)) - 0.5*(h./b(2)).^3).*(h<=b(2)) + (h>b(2))];
% SIMULATE FUNCTION
b = [10; 5]; % Created Parameters
h = linspace(0,7,25); % ‘h’ (Independent Variable)
gam2data = gamma2(b,h)+0.5*randn(1,length(h)); % Created Data (Dependent Variable)
B0 = [1; 1];
B = lsqcurvefit(gamma2, B0, h, gam2data); % Estimate Parameters
figure(1)
plot(h, gam2data,'bp')
hold on
plot(h, gamma2(B,h), '-r')
hold off
grid
  8 comentarios
Mani Ahmadian
Mani Ahmadian el 29 de Dic. de 2014
Editada: Mani Ahmadian el 29 de Dic. de 2014
Hi
I used above code on another data points and plot the result as bellow:
It's not a good fit based on my personal experiences. I think I have to change my view point to solve the problem.
Can I use regression functions to find the curve and use gamma2 as a limit for it?
gamma2 = @(b,h) b(1).*[(1.5*(h/b(2)) - 0.5*(h./b(2)).^3).*(h<=b(2)) + (h>b(2))];
If it is possible, please help me to do.
Thanks so much
Mani
Star Strider
Star Strider el 29 de Dic. de 2014
Your equation does not appear to accurately describe your data. I tried several options, including setting lower bounds on ‘b(1)’=C0=max(gam2data), and could not get a good fit.
I suggest you consider a different model. Your current model does not appear to describe the process that is generating the data you are fitting to it.

Iniciar sesión para comentar.


Matt J
Matt J el 26 de Nov. de 2014
Editada: Matt J el 26 de Nov. de 2014
Beware differentiability issues. Since your curve is not differentiable with respect to a0, the least squares cost function might not be either. It may be more trustworthy to use a derivative-free method like fminsearch instead,
gamma2 = @(b,h) b(1).*[(1.5*(h/b(2)) - 0.5*(h./b(2)).^3).*(h<=b(2)) + (h>b(2))];
A0=fminsearch( @(a0) norm(gamma2(a0,X)-Y) , initial_a0 )
  1 comentario
Star Strider
Star Strider el 26 de Nov. de 2014
I agree, but we’ve been there before in set parameters of nlinfit function. I decided not to fight it this time.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by