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

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Chunru
Chunru am 18 Mai 2022
Bearbeitet: Chunru am 18 Mai 2022
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

Weitere Antworten (0)

Kategorien

Mehr zu Gamma Functions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by