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

  • Context: MATLAB 
  • Thread starter Thread starter roam
  • Start date Start date
  • Tags Tags
    Air Matlab
Click For Summary

Discussion Overview

The discussion revolves around solving a problem related to the motion of an object thrown in the air using Matlab. Participants explore coding techniques, plotting results, and analyzing the behavior of the object's trajectory over time.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant presents a Matlab code snippet to model the trajectory of an object thrown at an angle, but notes that the plot only shows a single point.
  • Another participant suggests using the 'hold on' command within the loop to retain previous points on the plot.
  • A different participant proposes eliminating the loop entirely and instead using vectorized operations to calculate x and y values, while also noting that the time duration of 50000 seconds is excessive.
  • A participant acknowledges the suggestion and modifies the time duration to 20 seconds, expressing uncertainty about the graph indicating the object hits the ground after 1 second.
  • Another participant recommends reducing the time interval further and using smaller steps for t to improve the accuracy of the plot.
  • A later reply presents a different approach using a loop with a smaller time increment, asserting that the initial height is zero when t=0, suggesting that the original code may not account for the initial conditions properly.

Areas of Agreement / Disagreement

Participants express differing opinions on the best approach to plotting the trajectory and the interpretation of the results, indicating that there is no consensus on the optimal solution or the correctness of the initial code.

Contextual Notes

Participants discuss various time intervals and increments for t, highlighting the importance of these choices in accurately modeling the object's motion. There are unresolved questions regarding the interpretation of the graph and the initial conditions of the problem.

roam
Messages
1,265
Reaction score
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
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.
 
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.
 
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:
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;
 
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:

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 18 ·
Replies
18
Views
4K