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

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Chunru
Chunru il 18 Mag 2022
Modificato: Chunru il 18 Mag 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

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by