I am having a problem with a Matlab \"while\" loop. A projectile is being launch
ID: 3563643 • Letter: I
Question
I am having a problem with a Matlab "while" loop. A projectile is being launched from an angle "a" with a velocity of "v". The equations for height "h" and horizontal location "x" are functions of time.
Equations, h(t)=v*t* sin(a) -0.5*g*t^2 and x(t) = v*t*cos(a) Where h and x for time increments of 0.1 seconds for "a" = 20 degrees and v = 200 feet per second, g = 32.2 feet per second squared. Plot (t,h), (t,x), and (x,h).
We are only plotting from the time it launches until the time it hits the ground, there for we only care about values for "h" that are greater than zero, as negative would have the projectile in the ground.
I have the following script written but I am not getting any of the graphs.
clear;
%Given Information
t=0;%time in seconds
a=20;%angle in degrees
v=200;% feet per second
g=32.2;%feet per second squared
h=0;%height of projectile
i=0;%incremental starting point
while h>=0 ;
i=i+1;
tt(i) = (i+1)*0.1;
h(i) = v*(tt(i))*sind(a)-(.5*g*tt(i)^2);
x = v*(tt(i))*cosd(a);
end;
plot(tt,h)
hold on
plot(tt,x)
plot(x,h)
The help is greatly appreciated as I can't seem to find the problem and why it is not plotting. Thanks to those who reply..
Explanation / Answer
When you are using plot funtion .. you are trying to plt two arrays ..
So you should not use element wise plor instead use ..
Plot ( tt , h) ..
Do the same with oher plots and they will work fine
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.