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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by