Fitting data using polyfit, nlfit ?

6 次查看(过去 30 天)
I have 2 sets of data of the same size (X1, Y1) and (X2,Y2). (X1,Y1) has a linear relationship with zero intercept (Y1=slope*X1). How can I estimate the slope, R^2 value and plot it along with 95% confidence interval lines? Using Corrcoeff, polyfit and polyval gives me a relationship of the form Y1=slope*X1 + c, but I would like to force c=0.
(X2,Y2) has a non-linear relationship of the form Y2=A-Bexp(C*X2). Likewise, I would like to determine A,B & C along with R^2 value and plot it along with 95% confidence interval lines. I know I have to use nlinfit, nlparci but I am new in this and would need your help.
Thanks much.

采纳的回答

Star Strider
Star Strider 2012-10-1
编辑:Star Strider 2012-10-1
You seem to be acquainted with nlinfit and know how to use it, but apparently not with Anonymous Functions.
I suggest you use nlinfit for both problems. With B = [B(1) ... B(n)]' a column vector of parameters, your Y1 function becomes:
Y1 = @(B,x) B.*x;
since with only one parameter in it, you do not need to use subscripts.
Your Y2 function becomes:
Y2 = @(B,x) B(1)-B(2).*exp(B(3).*x);
These should work as your modelfun functions in nlinfit.
  15 个评论
Ganesh
Ganesh 2012-10-5
Is there a way to find the R^2 value for the fit?
Star Strider
Star Strider 2012-10-5
编辑:Star Strider 2012-10-5
R^2: Yes, if you use the NonLinearModel class, particularly NonLinearModel.fit. That will also give you a number of other statistics. I use it occasionally when I need the extra statistics it gives. There is a link to NonLinearModel at the end of the nlinfit documentation.
It is my pleasure to help!

请先登录,再进行评论。

更多回答(0 个)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by