Non-linear piecewise fit using fittype() and fit().

2 ビュー (過去 30 日間)
Justin Solomon
Justin Solomon 2012 年 9 月 14 日
Hello, I'm trying to fit some data to a rather complicated non-linear model:
y=(1-(x/R)^2)^n
where x is the independent variable with R and n constant. I need to fit this model to my data to find R and n. The problem I have is that this function returns complex values whenever n<1 and x>R. Thus I would like to make it a piecewise function so that c=0 when x>R. I can't figure out how to construct such a piecewise fit object using fittype(). Here's my code thus far for doing the fit:
ft = fittype( '(1-(x/R)^2)^n', 'independent', 'x', 'dependent', 'y' );
[fitresult, gof] = fit( xData, yData, ft)
Any ideas on how to do a non-linear piecewise fit? Thanks in advance for any insight.
Justin

採用された回答

Tom Lane
Tom Lane 2012 年 9 月 14 日
How about replacing
(x/R)^2
by
min(1,(x/R)^2)
  1 件のコメント
Justin Solomon
Justin Solomon 2012 年 9 月 15 日
Nice solution! Thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by