- #1
Lehane
- 2
- 0
I have two files, one the function m-file:
and the other
I need to find the x and y coordinates for the first 5 seconds (at 0,1,2,3,4) of a balls flight. I've tried creating matrices to call t, x2 and y2 but I just get errors...
Can anyone help?
Matlab:
function dy = yprimewithdrag(t,y)
% Provides derivatives dy(1) - dy(4) required to solve problem of
% projectile in flight.
% Variable definitions:
% y(1) = vx (horizontal velocity component)
% y(2) = vy (vertical velocity component)
% y(3) = x (horizontal position coordinate)
% y(4) = y (vertical position coordinate)
%
% Note: requires variable gravity to be defined
% and declared as global in main program
global mass gravity drag_coeff wind_speed
dy = zeros(4,1); % a column vector
dy(1) = -(drag_coeff/mass)*((((y(1)-wind_speed).^2)+(y(2).^2)).^0.5)*(y(1)-wind_speed);
dy(2) = -gravity-(drag_coeff/mass)*(((y(1).^2)+(y(2).^2)).^0.5)*y(2);
dy(3) = y(1)-wind_speed; %Wind speed subtracted so if head wind velocity decreases, and tail wind it increases
dy(4) = y(2);
and the other
Matlab:
global mass gravity drag_coeff wind_speed
mass = 50;
gravity = 9.81;
drag_coeff = 0.001;
wind_speed = 0;
% Define initial conditions
vi = 275;
theta = (2*pi)/9;
vxi = vi*cos(theta);
vyi = vi*sin(theta);
xi = 0;
yi = 0;
Y0 = [vxi vyi xi yi];
% Define time interval
time = [0:5];
% Solve numerically
[t y] = ode45('yprimewithdrag', time, Y0)
% Get the analytical solution for x and y
x1 = xi + vxi*time;
y1 = yi + vyi*time - 0.5*gravity*time.^2;
I need to find the x and y coordinates for the first 5 seconds (at 0,1,2,3,4) of a balls flight. I've tried creating matrices to call t, x2 and y2 but I just get errors...
Can anyone help?
Last edited by a moderator: