Azzera filtri
Azzera filtri

Index exceeds matrix dimensions

1 visualizzazione (ultimi 30 giorni)
MD NASAR
MD NASAR il 8 Mag 2012
Dear All I am trying to solve equation but i am getting error code is:
M=100;
r=0.8;
alpha=0.45;
beta=0.75;
gama=0.1;
d=0.004;
h=0.4;
n=100;
c(1)=1580;
c0=1500;
lembda=150;
delT=1;
x(1)=2;
a(1)=1000;
p(1)=100;
q(1)=0.8;
for t=1:20
q(t)=0.8;
xx=t+1;
x(xx)=x(t)+delT*(alpha+beta*log(a(t))+gama*x(t))*(M-x(t))*exp(-d*p(t))*exp(h*q(t))
%disp(x(t));
x(xx)
lembda(xx)=lembda(t)*(r*lembda(t)-exp(-d*p(t))*exp(h*q(t)*(gama*M-alpha-beta*log(a(t))-2*gama*x(t))*(p(t)-c(t)+lembda(t))+n*q(t)^x(t)-1*log(q(t))...
*(alpha+beta*log(a(t))+gama*x(t))*(M-x(t))*exp(-d*p(t))*exp(h*q(t))))
% disp('lembda(t+1)');
lembda(xx)
c(t)=n*q(t)^x(t)-1+c0
% disp('c(t)');
c(t)
p(t)=c(t)-lembda(t)+1/alpha
% disp('p(t)');
p(t)
a(t)=(p(t)-c(t)+lembda(t))*beta*(M-x(t))*exp(-d*p(t))*exp(h*q(t))
%disp('a(t)');
a(t)
end
when i am running this but i am getting error "??? Index exceeds matrix dimensions." actually i want the value of x(1) to x(20), lembda(1) to lembda(20), p(1) to p(20), c(1) to c(20),a(1) to a(20) please help me Thank you.

Risposte (1)

Andreas Goser
Andreas Goser il 8 Mag 2012
When I run this code in this line
x(xx)=x(t)+delT*(alpha+beta*log(a(t))+gama*x(t))*(M-x(t))*exp(-d*p(t))*exp(h*q(t))
because in the second time the loop gets executed, it want to have a(2), but a is still 1x1.
Why THAT is it is up to you, as I don't know what you want to achive.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by