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

3 次查看(过去 30 天)
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by