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 (최근 30일)
이전 댓글 표시
problem solved.Thanks
댓글 수: 1
Daniel Pollard
2021년 1월 13일
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.
답변 (2개)
Daniel Pollard
2021년 1월 12일
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.
댓글 수: 0
Cris LaPierre
2021년 1월 12일
편집: Cris LaPierre
2021년 1월 12일
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!