Subscript indices must either be real positive integers or logicals.

2 vues (au cours des 30 derniers jours)
Wojtek
Wojtek le 25 Nov 2015
Commenté : Wojtek le 25 Nov 2015
Hello. I am trying to write a script which will approximate a integro-differential equation using the general theta method. I have all the code written up already but for some reason I am getting this error "Subscript indices must either be real positive integers or logicals." in the following line
y(2)=(y(1)+theta1*h*h(-theta2*y(1)-(1-theta2)*y(1))+(1-theta1)*h*h*(-theta2*exp(-lambda*h)*y(1)))/(1+(1-theta1)*(1-theta2)*h*h);
I have set up all my initial values as follows:
h=0.05;
tmax=1000;
y=zeros(1,tmax/h+1);
y(1)=1;
lambda=1;
theta1=1;
theta2=1;
Can any one help please? Thank you

Réponse acceptée

Walter Roberson
Walter Roberson le 25 Nov 2015
h(-theta2*y(1)-(1-theta2)*y(1)) means to index h at location -theta2*y(1)-(1-theta2)*y(1)
MATLAB does not have implicit multiplication. Variable followed by '(' is indexing in MATLAB (or function call).
  1 commentaire
Wojtek
Wojtek le 25 Nov 2015
I see it now. I just forgot to put '*' in there. Thank you so much. It all works now! :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by