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 CenterFile Exchange 中查找有关 Gamma Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by