Forward Euler method error
Mostrar comentarios más antiguos
I am trying to create a loop to solve a system of differential equations, where x' = -y and y' = x. The initial conditions given are x(0) = r and y(0) = 0, but r can be set as any arbitrary number and it won't change the solution too much. I am getting this error that says "Array indices must be positive integers or logical values", but I am confused because I am nonly trying to set initial conditions. ANY help is greatly appreciated!!!

Respuesta aceptada
Más respuestas (1)
KSSV
el 28 de Abr. de 2022
The loop should be taken as:
for i = 1:round(N)
In your present case, it is a fraction and you are getting non integers as the indices and error is pooped.
% Demo
N = 10.2;
for i = 1:N
i
A(i) = rand ; % error, index cannot be fraction
end
Categorías
Más información sobre Mathematics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



