How to plot Projectile Motion?

I'm trying to create a function which is able to solely interpret the initial vertical and horizontal velocities of an object, then fully plot this motion. Here's what I have:
%User is prompted to input the initial velocities.
YVel = input('input initial vertical velocity ');
XVel = input('input initial horizontal velocity ');
%User is prompted for choice of planet in order to determine acceleration
%due to gravity
PlanetChoice = input('Where is this taking place? 1. Earth 2. Mars ');
if PlanetChoice == 1
YAccel = -9.8;
elseif PlanetChoice == 2
YAccel = -3.8;
end
%We assume that the object lands on the same height as the origin for this
%projection.
MaxHt = SCalc(0,YVel,YAccel);
TimeUp = TCalc(0,YVel,YAccel);
TimeDown = TCalc(-YVel,0,Accel);
TimeTot = TimeUp+TimeDown;
%Vectors are created for the vertical and horizontal displacement.
YVec = zeros(1, ceil(TimeTot/0.1));
XVec = zeros(1, ceil(TimeTot/0.1));
%Uses index values in order to loop and fill vectors.
TimeIndex = 0;
VecIndex = 1;
for TimeIndex <= ceil(TimeTot/0.1)
YVec(VecIndex) = SYFinal(YVel,Accel,TimeIndex);
XVec(VecIndex) = SXFinal(XVel,TimeIndex);
TimeIndex = TimeIndex + 0.1;
VecIndex = VecIndex + 1;
end
plot(XVec,YVec)
The error that I'm having return to me, refers to the for loop. " invalid left hand side of assignment
plot(XVec,YVec)cIndex + 1;0.1;l,TimeIndex);ndex);ht as the origin for this"
Not sure how to fix this. Please excuse the length and ridiculous amount going on, as I'm expected to write this much for this piece of work.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 28 de Mayo de 2017

0 votos

for is used to indicate repetition where the iteration values are known ahead of time, such as
for k=1:10
for word=[7, 2, 11]
When you want to repeat as long as a condition is satisfied then you need to use while

Más respuestas (0)

Categorías

Más información sobre Physics en Centro de ayuda y File Exchange.

Preguntada:

el 28 de Mayo de 2017

Respondida:

el 28 de Mayo de 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by