Problem 46938. Numerical computation of the optimal shooting angle of a catapult
Consider a capapult that fires a projects into the air with an initial velocity
. The free-flying projectile is subjected to air friction and a gravitional force. Given a desired target
and an initial velocity
, find the optimal shooting angle
of the catapult that minimizes the distance between the target and the trajectory of the fired projectile.
tip 1: Consider the states
and
as the x- and y-position of the projectile, and
and
as the x- and y-velocity. Then, the trajectory of the projectile can be found by solving the following ordinary differential equation (ODE):
where
, and
is the friction coefficient between the air and the projectile. Use the ode45.m function to compute the trajectory of the projectile with initial conditions
. Plotting
vs.
will result in the x-y trajectory of the projectile, as shown in the figure below.
tip 2: Use the following update law, to incrementally update the shooting angle
:
where
the smallest Euclidean distance between the trajectory of the projectile and the target
,
is a difference angle, and
an update parameter.
Example of algorithm's numerical result:
theta = catapult(25,3,25)
theta =
0.8431
Solution Stats
Problem Comments
-
2 Comments
Alex
on 19 Oct 2020
Nice problem. There should be much more problems involving solution of differential equations on Cody. :-)
William
on 7 Mar 2024
I have tried many ways of getting isequal( round(...,2),y_correct) to evaluate to 'true' when round(...,2) is, in fact, equal to y_correct. But, they all fail on the Cody server. Why not just test whether abs(catapult(...) - y_correct) <= TOL.
Solution Comments
Show commentsProblem Recent Solvers7
Suggested Problems
-
2630 Solvers
-
2964 Solvers
-
147 Solvers
-
Arrange vector in ascending order
784 Solvers
-
651 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!