MATLAB Answers

A code and plot a graph for a projectile motion of a ball

9 ビュー (過去 30 日間)
TANAMAY KOTHARI
TANAMAY KOTHARI 2021 年 6 月 2 日
編集済み: James Tursa 2021 年 6 月 11 日
How do I write a code and plot a graph for a projectile motion of a ball thrown at 60 deg with a speed of 50 m/s using ode and runge kutta method.
Somebody please help
  6 件のコメント
Scott MacKenzie
Scott MacKenzie 2021 年 6 月 2 日
You state that "the plot that appears comes blank". But, actually, there is no plot generated because the plot function never executes. You've got bugs in your code. Good luck.
BTW, you might want to have a look here -- a related question.

サインインしてコメントする。

回答 (1 件)

James Tursa
James Tursa 2021 年 6 月 11 日
編集済み: James Tursa 2021 年 6 月 11 日
Your main problem is that you don't have enough state variables. You have these two equations:
x'' = 0
y'' = -g
That's two 2nd order equations, so you need to have 2 * 2 = 4 state variables. The state variables you need to integrate are x, y, Vx, Vy. But you only integrate two of these state variables, x and y. You have no code for integrating Vx and Vy. You need to add code for integrating Vx and Vy.
You also are using the solution of x and y integration as the derivative functions, which is incorrect. For a Runge-Kutta method, just use the derivatives. The code would be patterned after:
x' = Vx
y' = Vy
Vx' = x'' = 0
Vy' = y'' = -g
You also use g for both gravity and a function handle, so to avoid confusion you might want to change one of these.

Community Treasure Hunt

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

Start Hunting!

Translated by