Extract coordinates at time intervals

In summary: Make sure to define the global variables mass, gravity, drag_coeff, and wind_speed before running the ode45 function. In summary, to find the x and y coordinates for the first 5 seconds of a ball's flight, use the ode45 function with the yprimewithdrag function and then access the x and y coordinates from the output. Make sure to define the global variables before running the ode45 function.
  • #1
Lehane
2
0
I have two files, one the function m-file:

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:
Physics news on Phys.org
  • #2
You can use the ode45 function to solve your problem. The syntax is as follows: [t,y] = ode45(@yprimewithdrag, time, Y0) where time is a vector of the time points you want to solve for, Y0 is the initial conditions, and @yprimewithdrag is a function handle to the function yprimewithdrag. Once you have run the ode45 function, you can then access the x and y coordinates from the output y. For example,x2 = y(:,3);y2 = y(:,4);will give you the x and y coordinates for the first 5 seconds of the ball's flight.
 

Related to Extract coordinates at time intervals

1. What is the purpose of extracting coordinates at time intervals?

The purpose of extracting coordinates at time intervals is to track the movement or changes in location of an object or phenomenon over a specific period of time. This can provide valuable information for various scientific studies and experiments.

2. How do you extract coordinates at time intervals?

The process of extracting coordinates at time intervals involves collecting data at regular time intervals using a tracking device or software. The collected data can then be plotted on a graph or analyzed using specialized software to determine the coordinates at specific time points.

3. What types of devices or software are commonly used to extract coordinates at time intervals?

There are various types of devices and software that can be used to extract coordinates at time intervals. These include GPS devices, satellite imagery, remote sensing technology, and specialized tracking software. The specific device or software used will depend on the specific needs and requirements of the study or experiment.

4. Can coordinates be extracted at irregular time intervals?

Yes, coordinates can be extracted at irregular time intervals. This may be necessary in situations where the object or phenomenon being tracked does not follow a regular pattern or if there are external factors that affect its movement. However, it is important to note that using regular time intervals can provide more accurate and consistent results.

5. What are some potential applications of extracting coordinates at time intervals?

Extracting coordinates at time intervals has numerous applications in various fields of science. It can be used in ecology to track animal movement and migration patterns, in geology to monitor changes in landforms, and in meteorology to track the path of weather systems. It can also be used in transportation planning, disaster management, and many other areas where tracking and analyzing movement is important.

Similar threads

  • Classical Physics
Replies
7
Views
759
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Calculus and Beyond Homework Help
Replies
4
Views
1K
  • Introductory Physics Homework Help
Replies
14
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Replies
2
Views
918
  • Calculus and Beyond Homework Help
Replies
3
Views
609
  • Introductory Physics Homework Help
Replies
6
Views
511
  • Calculus and Beyond Homework Help
Replies
3
Views
400
Replies
8
Views
304
Back
Top