Solving a Problem with Matlab: An Object Thrown in the Air

  • MATLAB
  • Thread starter roam
  • Start date
  • Tags
    Air Matlab
In summary, the conversation is about using Matlab to solve a problem involving an object thrown in the air. The code provided by the person has a problem with producing a proper plot, as it only shows a single dot. The expert suggests either using a loop with the "hold on" command or simply dropping the loop entirely. The person then mentions that they have changed the time interval to 20 seconds and provides a graph, but is unsure if it is correct. The expert suggests breaking the time interval down into smaller steps and provides a code for the loop. The final result is a graph that shows the height of the object over time, with the initial event of the object being thrown not being considered in the code.
  • #1
roam
1,271
12
I want to solve the following problem using Matlab:

Here's the question regarding an object thrown in the air:

http://img197.imageshack.us/img197/7797/97452743.gif

My code:

Code:
theta=pi/4; v=10;  g=9.81;   a=0.1; 
nfinal=50000;
for t=1:nfinal
    x=((1-exp(-a*t))/a)*v*cos(theta);
    y=((1-exp(-a*t))/a)*((g/a)+v*sin(theta))-((g*t)/a);
end
plot(t,y,'+')

It doesn't produce a proper plot, all I can see is a dot. What is the problem with my code?
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
The way you are doing it, x and y are single points and you keep redefining them before you plot them. If you want to do it that way, you need to put
plot(t,y,'+'), hold on
inside the loop. The hold on is important in order to keep the previous point on the plot.
 
  • #3
Actually, even better would be to simply drop the loop completely:
Code:
theta=pi/4; v=10;  g=9.81;   a=0.1; 
nfinal=50000;

t=1:nfinal;
x=((1-exp(-a*t))/a)*v*cos(theta);
y=((1-exp(-a*t))/a)*((g/a)+v*sin(theta))-((g*t)/a);
plot(t,y,'+')

BTW, 50000 seconds is way too long.
 
  • #4
Oh thanks Matonski! Yeah, it's too long and I changed it to 20 seconds, so here's the graph:

http://img261.imageshack.us/img261/2768/33588615.png

I'm looking for the time when it hits the ground (when the height =0, or the root/x-intercept of the graph). But this graph shows that height=0 after 1 second, I'm not so sure if this is right... :confused:
 
Last edited by a moderator:
  • #5
you need to break the time interval down shorter. Try setting nfinal to like 2 seconds and have t go in smaller steps like this:
t=1:.01:nfinal;
 
  • #6
This is my result:

http://img141.imageshack.us/img141/8242/46816894.th.jpg

My code for the loop is

Code:
for t = 0 : 0.1 : 2
     <calculate and plot>
end

When t = 0, the height is zero. It means that the object starts being thrown. Therefore, I think your code has no problem but you just don't consider the initial event of the object.
 
Last edited by a moderator:

1. How does Matlab calculate the trajectory of an object thrown in the air?

Matlab uses the equations of motion, specifically the projectile motion equations, to calculate the trajectory of an object thrown in the air. These equations take into account the initial velocity, angle of elevation, and acceleration due to gravity to determine the position of the object at any given time.

2. Can Matlab account for air resistance in its calculations?

Yes, Matlab has the capability to account for air resistance in its calculations by incorporating a drag force term into the equations of motion. This drag force depends on the object's velocity and the properties of the fluid it is moving through.

3. How accurate are the results from Matlab's calculations?

The accuracy of the results from Matlab's calculations depends on the accuracy of the input parameters and the precision of the calculations. In general, Matlab's calculations are very accurate, but small variations in the input values can lead to slightly different results.

4. Can Matlab plot the trajectory of an object thrown in the air?

Yes, one of the strengths of Matlab is its ability to plot data and create visual representations of calculations. Using the calculated position values, Matlab can plot the trajectory of an object thrown in the air in 2D or 3D.

5. Is Matlab the best tool for solving problems involving an object thrown in the air?

While Matlab is a powerful tool for solving a wide range of scientific and engineering problems, it may not be the best tool for every specific problem. It is important to assess the specific needs of the problem and consider other options before determining if Matlab is the best tool for the job.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
737
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
Back
Top