I'm trying to track a particle's velocity at each time step, but my X&Y Velocity Variables keep becoming matrices, instead of overwriting each time. How should I fix this?
12 ビュー (過去 30 日間)
古いコメントを表示
The code that keeps giving me and error is
Counter = Counter + 1
TrackedVelocity(Counter) = sqrt((VelocityX)^2+(VelocityY)^2);
5 件のコメント
Walter Roberson
2021 年 11 月 27 日
Suppose ParticleMass is non-scalar, then the / operator would be matrix division rather than element-by-element division, and that could lead to unexpected results.
採用された回答
Walter Roberson
2021 年 11 月 27 日
TrackedVelocity(Counter) = sqrt((VelocityX)^2 + (VelocityY)^2);
So TrackedVelocity is a vector that is increasing in size.
if VelocityY < 0
DragForceY = -(DragCoefficient*(TrackedVelocity)*(VelocityY));
elseif VelocityY > 0
DragForceY = -(DragCoefficient*(TrackedVelocity)*(VelocityY));
end
You use all of the vector TrackedVelocity in DragForceY so DragForceY is going to increase in size as you go. That is going to trigger other variables to increase in size.
Question:
Your two if branches have the same code. Therefore the difference between doing the code unconditionally and doing the code the way you do it now, is in the behaviour if neither branch of the if is met -- which would occur if VelocityY == 0 exactly or VelocityY became NaN somehow. Are you sure that in either of those cases, that you want to leave DragForceY at its previous value ?
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!