how to use the function 'nlinfit' in matlab?

Status
Not open for further replies.

melodyseu

Junior Member level 3
Joined
Jul 22, 2004
Messages
31
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
233
nlinfit

I'm dealing with the curve-fitting using the function--nlinfit in matlab.
Here is the syntax : beta = nlinfit(X,y,'model',beta0), and I don't know how to define the term 'model'.
Can you give me some advice,thanks.
 

nlinfit example

Hi there,

You need to define your 'model' as a function (possibly in a seperate m-file). For example

>>beta = nlinfit(X,y,myfun,beta0)

where MYFUN is a MATLAB function such as:
function yhat = myfun(beta, X)
b1 = beta(1);
b2 = beta(2);
yhat = 1 ./ (1 + exp(b1 + b2*X));


MYFUN can also be an inline object:
fun = inline('1 ./ (1 + exp(b(1) + b(2*x))', 'b', 'x')
nlinfit(x, y, fun, b0)

HTH
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…