Hello,
I'm new to matlab and i'm struggling very much with it.
I have been assigned a coursework in which i must find the trajectory of a projectile.
The coursework looks like this:
The path of a projectile is an interesting, important, and sometimes challenging problem. It’s very likely that you will have studied the path of a projectile in the absence of atmospheric drag in basic mechanics, since this can be derived analytically. In the real world, however, drag can significantly alter the trajectory. Unfortunately, in introducing this effect, we lose the ability to analytically obtain solutions for the projectile’s trajectory: simulating the trajectory is therefore required. In this assignment, you will therefore write a Matlab program that computes trajectories under the influence of drag, and use this to solve a simple targeting problem.
We will neglect any crosswind effects, so that the projectile travels in a two-dimensional plane with coordinates (x, y). The projectile’s position, velocity and acceleration can therefore be represented as vector functions of time, which we denote by r(t) = [rx(t), ry(t)], v(t) = [vx(t), vy(t)] and a(t) respectively. As the projectile travels through space, we will assume that it experiences two forces: acceleration due to gravity, and a drag force Fd acting in the direction opposite to its trajectory. A free body diagram of this scenario can be found in Figure 1. The drag force can be roughly approximated by the drag coefficient Cd through the relationship : Fd = 1/2 (ρ*Cd*A*|v|*v)
which also involves the velocity v, air density ρ and the frontal area A (i.e. the two-dimensional cross-section exposed to the drag force). cd is dimensionless and is used to quantify the drag of an object in a fluid: the lower the value, the lower the drag force. To simulate the trajectory of the projectile, we can use Newton’s second law: F = ma ⇒ a(t) = (1/m)*(((− 1/2)* ρcdA|v|v) − mg ). where m is the mass of the projectile and g = (0, g) is acceleration due to gravity with g = 9.81 ms−2 . Since we are interested in the projectile’s trajectory r, we can then utilise the fact that a(t) = dv/dt = v'(t) and v(t) = dr/dt = r'(t) , which gives a ordinary differential equation r''(t) = (1/m)*(((− 1/2)* ρcdA|r'|r') − mg ). equation (1)!
All that is left to do is equip the above with an appropriate set of initial conditions at time t = 0: we will imagine that the projectile is fired from an initial starting height h at an angle of θ degrees and initial speed (velocity magnitude) v0, which gives: r(0) = (0, h) and r˙(0) = v(0) = [v0 cos(θ), v0 sin(θ)]
can someone please help me with it as im totally lost on how to implement this into matlab language?

4 commentaires

Jon
Jon le 20 Jan 2021
Please attempt to write some code and then ask for specific help with the problems you encounter with your code. If you don't know enough about MATLAB to get started then please complete the MATLAB On Ramp training https://www.mathworks.com/learn/tutorials/matlab-onramp.html
If you don't understand the mathematics of the problem then you should ask your Professsor, Teaching Assistants and fellow students for assistance.
Nicolae Lungu
Nicolae Lungu le 21 Jan 2021
i have written this function but its giving errors and i cant understand what im doing wrong....
function dydt = drag_ode(t, y)
% equations of motion for projectile
m= .005; % mass of the projectile
g= 9.81; % acceleration due to gravity constant
t(1)= 0; % initial time
rho = 1.225; % density of atmosphere near Earth surface(kg/m^3)
Cd= .479; % Drag coefficient
D= .1; % Diametet m
A=pi*(D/2)^2; % Area of sphere, A=0.0314 (m)
k = rho * A * Cd; % assuming 'k' as the combined constant
dydt=zeros(4,1); %the vector in column form
% Equations of Motion State Variable Form
dydt(1)=y(2); % velocity on x axis
dydt(2)=(-.5*k/m)*sqrt( ((y(4))^2) + ((y(2))^2) )*y(2); % velocity on y axis
dydt(3)=y(4); % position on x axis
dydt(4)=-g-(.5*k/m)*sqrt( ((y(4))^2) + ((y(2))^2) )*y(4); % position on y axis
end
The error message that im getting is:
Not enough input arguments.
Error in drag_ode (line 15)
dydt(1)=y(2);
can you help me please?
Image Analyst
Image Analyst le 21 Jan 2021
Looks like a duplicate of your other question where I asked you what was t and y.
Nicolae Lungu
Nicolae Lungu le 21 Jan 2021
Because basically they both are functions im tryng to implement for the assignment above, but i can't understand where im doing wrong and how to fix them.....

Connectez-vous pour commenter.

 Réponse acceptée

Image Analyst
Image Analyst le 20 Jan 2021

2 votes

Attached is a program my son and I did for his college physics course. It computes just about everything you could possibly want to know about a projectile, with all kinds of parameters (starting angle, height, velocity, etc.) and graphs. Adapt as needed.

3 commentaires

Nicolae Lungu
Nicolae Lungu le 21 Jan 2021
thank you very much sir, you and your son.
As a very new matlab user it is very useful to see how the actual way of coding should look like.
Joseph Durocher
Joseph Durocher le 17 Nov 2022
Is there a way to change the calculation to add drag force?
Image Analyst
Image Analyst le 17 Nov 2022
Probably. Use whatever formula you have. I don't have one. Feel free to adapt the code to your own needs.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Produits

Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by