MATLAB: Subscript indices must either be real positive integers or logicals help line u1(0)=2

matlab euler

clear
close all;
h = 0.5;
N = 10;
u1(0)= 2 ;
u2(0)= 3 ;
t(0) = 2;
for n=0:10
u1(n+1)=u1(n) +h*u2(n);
u2(n+1)=u2(n) +h*(4*exp(0.8*t(n))-(0.5)*u1(n));
t(n+1)= t(n) + h ;
end
plot(u1,u2);

Best Answer

Positive integers are integers greater than 0.
This works:
h = 0.5;
N = 10;
u1(1)= 2 ;
u2(1)= 3 ;
t(1) = 2;
for n=1:10
u1(n+1)=u1(n) +h*u2(n);
u2(n+1)=u2(n) +h*(4*exp(0.8*t(n))-(0.5)*u1(n));
t(n+1)= t(n) + h ;
end
plot(u1,u2);