Non Linear regression

% name: myfun.m file
function yhat = myfun(beta,X)
b1 = beta(1); %(Feight multiplier)
b2 = beta(2); %(Freight rate multiplier)
e = X(1); %(Economic growth)
p = X(2); %(Previous year freight)
r = X(3); %(Real freight rate change)
yhat = p*(1.0+(e*b1))*(1.0+(r*b2));
inputs are
x=(11,3) Matrix
y= (11,1) Matrix
beta0 = rand(11,2) Matrix
when i run the script i get the following;
beta = nlinfit(X,y,'myfun',beta0)
??? Error using ==> nlinfit at 127
MODELFUN should return a vector of fitted values the same length as Y.
I dont understand what the error is can someone please help.
Thanks in advance

 採用された回答

Greg Heath
Greg Heath 2011 年 10 月 14 日

0 投票

% name: myfun.m file
function yhat = myfun(beta,X)
b1 = beta(1); %(Freight multiplier)
b2 = beta(2); %(Freight rate multiplier)
e = X(:,1); %(Economic growth)
p = X(:,2); %(Previous year freight)
r = X(:,3); %(Real freight rate change)
yhat = p.*(1.0+(e*b1)).*(1.0+(r*b2));
inputs are
x=(11,3) Matrix
y= (11,1) Matrix
beta0 = rand(11,1) Matrix
Hope this helps
Greg

その他の回答 (1 件)

bym
bym 2011 年 10 月 13 日

0 投票

try changing these lines:
e = X(1); %(Economic growth)
p = X(2); %(Previous year freight)
r = X(3); %(Real freight rate change)
to
e = X(:,1); %(Economic growth)
p = X(:,2); %(Previous year freight)
r = X(:,3); %(Real freight rate change)
(untested)

カテゴリ

ヘルプ センター および File ExchangeGet Started with MATLAB についてさらに検索

製品

質問済み:

2011 年 10 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by