Index in position 1 is invalid. Array indices must be positive integers or logical values. (Slution of equation of motion with runge kutta 4)

1 visualización (últimos 30 días)
problem solved.Thanks
  1 comentario
Daniel Pollard
Daniel Pollard el 13 de En. de 2021
When you find a solution to a problem, it's bad practice to delete the question and not say what helped you.
If someone has the same problem and googles their error message, your question may pop up as a result, which they click on hoping to see how you fixed your problem.
In future please don't delete questions like this, and please do accept either Cris or my solution if it helped you, again so others can be helped by you.

Iniciar sesión para comentar.

Respuestas (2)

Daniel Pollard
Daniel Pollard el 12 de En. de 2021
t(1), q(1) and dqdt(1) are all zero. Matlab indexing starts at 1, so when you assign
k_11 = y1_2nd(t(i),q(i),dqdt(i))
it tries to go to y1_2nd(0, 0, 0), and so fails.
That's what's causing the error. I can't fix it because it's not clear what the intention was.

Cris LaPierre
Cris LaPierre el 12 de En. de 2021
Editada: Cris LaPierre el 12 de En. de 2021
It looks like you are trying to use y1_2nd as both a funtion and a variable name.
It is created as the result of calling function f1_2, which has 3 inputs. Then inside your for loop, you treat y1_2nd as if it is the function f1_2, calling it with the same 3 inputs. However, it is a vector of numbers (1x100).
The error is saying your index in position 1, or t(i), is not valid. Given the dimensions of your vector, it must be 1. And there is no 3rd dimension, so you will get an error about that soon.

Community Treasure Hunt

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

Start Hunting!

Translated by