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

3 views (last 30 days)
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);

Accepted Answer

Star Strider
Star Strider on 6 Apr 2019
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);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!