insert two criteria function to lsqcurvefit

2 views (last 30 days)
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

Answers (2)

Star Strider
Star Strider on 26 Nov 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 Comments
Mani Ahmadian
Mani Ahmadian on 29 Dec 2014
Edited: Mani Ahmadian on 29 Dec 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 on 29 Dec 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.

Sign in to comment.


Matt J
Matt J on 26 Nov 2014
Edited: Matt J on 26 Nov 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 )

Categories

Find more on Interpolation 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!