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