Matlab Projectile Motion Table and Graph

  • MATLAB
  • Thread starter juice34
  • Start date
  • Tags
    Matlab
In summary, the conversation is about a program that needs to print out a formatted table of time, distance, and velocity. The code is given, but the problem is figuring out how to print out the table. The conversation includes getting user inputs, calculating initial velocities and range, and creating masks to determine the accuracy of the projectile. The solution suggested is to use a formatted print.
  • #1
juice34
I have a program that needs to print out a formated table of time x distance and ydistance. I got everything written except for figureing out how to print out formatted tables could somebody help me here is the code.

%Constants and initial values
g = -9.8;
conv = (pi/180);


%Get users inputs in the following order:distance,velocity,angle
try
distance = input ('Please enter the distance to your target: (meters) \n');
m = Distance <= 0;
if m == 1
disp ('::FATAL ERROR: Distance cannot be < or = to zero, goodbye')
break
end
catch ME
end


try
velocity = input ('Please enter initial velocity of the projectile: (m/s) \n');
m = velocity <= 0;
if m == 1
disp ('::FATAL ERROR: Velocity cannot be < or = to zero, goodbye')
break
end
catch ME
end

try
theta = input ('Please enter an angle (degrees) between 0 and 90: \n');
m = theta < 0 | Theta > 90;
if m == 1
disp ('::FATAL ERROR: Angle cannot be < or = to zero, goodbye')
break
end
catch ME
end

%Calculate initial x and y velocitys, time, and range
voy = velocity*sin(theta*conv);
vox = velocity*cos(theta*conv);
time = -2*(voy / g);
range = (vox*time)

%Show how far bag traveled
fprintf ('The bean bag traveled a total of %6.2f meters \n',range)

%Create masks to determine how close projectile was to target
ma = (range-2.5 <= Distance && Distance <= range+2.5);
mb = (range > Distance-2.5);
mc = (range < Distance+2.5);

%Interpret masks
if ma == 1
fprintf ('Your bag hit the target right on! GOOD AIM')
elseif mb == 1
fprintf ('so your bean bag traveled long %6.2f meters \n', abs(range - distance))
elseif mc == 1
fprintf ('so your bean bag traveled short %6.2f meters \n', abs(distance - range))
end

disp 'Please press enter to see (x,y) coordinates as a funtion of time:'
pause


%TABLE/GRAPH%

xpos = 0; %Set starting location at (x,y)=(0,0)
ypos = 0;

t=0; %Random incrementing variable(represents time).


for t=0:.1:100
t=t+1;

vy = voy + (g*t);
xpos = xpos + (vox*.1);
ypos = ypos + (voy*.1);
out = [t' xpos' ypos']

fprintf ( 'The x value is %6.2d and y value is %6.2d n\',out(t,:))

if( ypos < 0 )
break;
end
end
 
Physics news on Phys.org
  • #2
A formatted print should do the trick.
 
  • #3
DrClaude said:
A formatted print should do the trick.

DrClaude,

I have been waiting for this reply going on about 11 years or so! I can turn in my homework!
 
  • Haha
Likes DrClaude
  • #4
We're doing some spring cleaning to reduce the number of old unanswered threads. Hopefully, even though this is no longer of help to you, someone else might stumble upon this thread and find it useful.
 

1. What is Matlab Projectile Motion Table and Graph?

Matlab Projectile Motion Table and Graph is a tool used in Matlab software to calculate and plot the trajectory of a projectile motion. It helps in visualizing the motion of an object thrown in the air under the influence of gravity.

2. How is the trajectory of a projectile calculated?

The trajectory of a projectile can be calculated using the equations of motion, which take into account the initial velocity, angle of projection, and acceleration due to gravity. These equations are solved using Matlab to generate a table of values and a graph of the projectile's path.

3. What are the inputs required for Matlab Projectile Motion Table and Graph?

The inputs required are the initial velocity, angle of projection, and acceleration due to gravity. These values can be entered manually or through a data file in Matlab.

4. Can multiple projectiles be plotted on the same graph?

Yes, Matlab Projectile Motion Table and Graph allows for multiple projectiles to be plotted on the same graph. This can be useful for comparing the trajectories of different objects or for analyzing the effect of changing the initial conditions on the trajectory.

5. Is Matlab Projectile Motion Table and Graph accurate?

Matlab Projectile Motion Table and Graph uses mathematical equations to calculate the trajectory of a projectile, so it is accurate as long as the input values are correct. It also takes into account the effects of air resistance, making it more accurate than simple calculations.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
954
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top