0

This is my code for Euler method but I keep getting

Error :"Subscript indices must either be real positive integers or logicals."

%Define parameters                                                           
A=1250; %m^2         
Q=450; %m^3/d                                                             
a=150;           
y(i)=0;          
t(i)=0;               
t=[0:0.5:10]';                              
%Set loop in (Eulers method) for the amount of steps we want to do to
%find our estimated solution                            
for i=1:20               
y(i+1)=y(i)+((3*(Q/A)*sin(t(i)).^2)-(a*(1+y(i)).^1.5/A))*0.5                  
end                    
%generate table for data             
disp('t            y')                     
disp('---------------')                 
disp([t,y])                      
y=y'                       
plot(t,y)                                 
title('Plot of y vs t')                                  
xlabel('time')                            
ylabel('y')
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271

1 Answers1

0

You have y(i)=0 and t(i)=0 Did you mean to say: y(1)=0; t(1)=0;

Since you define t in the next lines don't even bother defining the 1st index of t, t(1)

So remove line 6 t(i) = 0 And change line 5: y(i)toy(1)

Mike James Johnson
  • 724
  • 2
  • 8
  • 29