필터 지우기
필터 지우기

insert two criteria function to lsqcurvefit

조회 수: 2 (최근 30일)
Mani Ahmadian
Mani Ahmadian 2014년 11월 26일
댓글: Star Strider 2014년 12월 29일
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

답변 (2개)

Star Strider
Star Strider 2014년 11월 26일
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
Mani Ahmadian
Mani Ahmadian 2014년 12월 29일
편집: Mani Ahmadian 2014년 12월 29일
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 2014년 12월 29일
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.

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


Matt J
Matt J 2014년 11월 26일
편집: Matt J 2014년 11월 26일
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
Star Strider
Star Strider 2014년 11월 26일
I agree, but we’ve been there before in set parameters of nlinfit function. I decided not to fight it this time.

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

Community Treasure Hunt

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

Start Hunting!

Translated by