why I receive this error "Array indices must be positive integers or logical values"?

1 回表示 (過去 30 日間)
i'm trying fo run this function but i obtain this error "Array indices must be positive integers or logical values"
function c1a = c1a(w,r,gamma,beta)
c1a = (w + (w/(1+r)))/(1 + ((1/(1+r))*((beta(1+r))^gamma)) + ((1/(1+r)^2)*(beta*(1+r))^(2*gamma)));
end
gamma = 0.5;
beta = 0.9;
w = 0.3;
r = 1.2;
[c1star] = c1a(w,r,gamma,beta)
%this is the error
Array indices must be positive integers or logical values.
Error in c1a (line 2)
c1a = (w + (w/(1+r)))/(1 + ((1/(1+r))*((beta(1+r))^gamma)) + ((1/(1+r)^2)*(beta*(1+r))^(2*gamma)));
Error in pseHomework (line 6)
[c1star] = c1a(0.3,1.2,0.5,0.9)
thanks to everyone

採用された回答

Chunru
Chunru 2022 年 5 月 18 日
編集済み: Chunru 2022 年 5 月 18 日
gamma = 0.5;
beta = 0.9;
w = 0.3;
r = 1.2;
[c1star] = c1a(w,r,gamma,beta)
c1star = 0.2130
function c1a = c1a(w,r,gamma,beta)
% *
c1a = (w + (w/(1+r)))/(1 + ((1/(1+r))*((beta*(1+r))^gamma)) + ((1/(1+r)^2)*(beta*(1+r))^(2*gamma)));
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGamma Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by