From: Steven Lord on 18 May 2010 10:08 "strat " <e-goum(a)hotmail.com> wrote in message news:hstgcc$r9o$1(a)fred.mathworks.com... *snip* > It seems i am doing something wrong. I have 3 variables: > Name of variables: > y--> vector 50x1 > x1--> vector 50x1 > x2--> vector 50x1 > ---- > X--> design matrix 50x2 (x1,x2 variables) > bInt--> vector 5x1 (initial values) (1 1 1 1 1) > > i wrote the above code you sent me to an M-file and i got some errors when > i run it: > CODE: function yhat = mynlinfunc(beta,X) > beta0 = beta(1); > beta1 = beta(2); > beta2 = beta(3); > beta3 = beta(4); > beta4 = beta(5); > yhat = beta0+beta1*X(:,1).^beta2+beta3*X(:,2).^beta4; > BetaHat = nlinfit(X,y,@mynlinfunc,bInt); Your NLINFIT call should NOT appear in the function whose handle you pass into NLINFIT. Otherwise, mynlinfunc would call NLINFIT which would call mynlinfunc which would call NLINFIT which would call mynlinfunc which would call NLINFIT which would call mynlinfunc which would call NLINFIT which would call mynlinfunc which would call NLINFIT ... you see the problem. Move your NLINFIT call OUT of the mynlinfunc function into a separate script or function file. Then define X, y, and bInt inside that separate script or function and then call NLINFIT. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
From: strat on 19 May 2010 03:23 O.K. I think i found what was wrong. In the code i wrote two more lines: CODE (M-file) function yhat = mynlinfunc(beta,X) b1 = beta(1); b2 = beta(2); b3 = beta(3); b4 = beta(4); b5 = beta(5); ---NEW LINES X1 = X(:,1); X2 = X(:,2); ----- yhat = b1+b2*X(:,1).^b3+b4*X(:,2).^b5; (Hope it is fine now...) Then i run it (Matlab Command Window: BetaHat = nlinfit(X,y,@mynlinfunc,bInt)) and i estimate the coefficients. One more thing i would like to ask. How do i get the stats (tstat,F-stat, R^2 etc) of the regression yhat = b1+b2*X1^b3+b4*X2^b5?
First
|
Prev
|
Pages: 1 2 3 Prev: execute standalone app without command prompt Next: executable on multiple platforms |