insert two criteria function to lsqcurvefit
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (2개)
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
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
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
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!