Plotting Velocity-Time Curve for multiple angles.

9 vues (au cours des 30 derniers jours)
Callum Ogilvie
Callum Ogilvie le 3 Avr 2017
Réponse apportée : KSSV le 4 Avr 2017
I have an assignment where I have to plot multiple curves generated by providing multiple angles to a function.
function[ycord,xcord] = Q2(initialvel, time, launchangle, initialposx, initialposy, gravity, velocityx, velocityy)
%Initial Vel = vectored initial velocity
%Initial y = initial y-axis position
%initial x = initial x-axis position
%veloctiy x = velocity of x
%velocity y = velocity of y
%time = time (seconds)
%Gravity = gravity (ms-2)
%theta = launch angle
%For question purposes, theta values have to be asked for.
%The values for everything apart from theta have also been added.
initialposx = 50;
initialposy = 100;
gravity = -9.81;
initialvel = 1;
time = 1;
for d = 1:3
hold on
launchangle = input('Please input a Launch Angle between 1 and 90')*(pi/180);
%Formula to calculate x velocity
velocityx = initialvel*cos(launchangle)
%Formula to calculate y velocity
velocityy = initialvel*sin(launchangle)
%Formula to calculate y-cordinate
ycord = initialposy + velocityy * time - (1/2*gravity*(time^2))
%Formula to calculate x-cordinate
xcord = initialposx + velocityx * time
title('Angry Birds Knockoff Matlab Game');
plot(xcord,ycord, '--rs', 'linewidth', 2);
end
How can I plot this so that it shows as a curve, and not just a final point??
Thanks

Réponses (1)

KSSV
KSSV le 4 Avr 2017
clc; clear all
function[ycord,xcord] = Q2(initialvel, time, launchangle, initialposx, initialposy, gravity, velocityx, velocityy)
%Initial Vel = vectored initial velocity
%Initial y = initial y-axis position
%initial x = initial x-axis position
%veloctiy x = velocity of x
%velocity y = velocity of y
%time = time (seconds)
%Gravity = gravity (ms-2)
%theta = launch angle
%For question purposes, theta values have to be asked for.
%The values for everything apart from theta have also been added.
initialposx = 50;
initialposy = 100;
gravity = -9.81;
initialvel = 1;
time = 1;
xcord = zeros(3,1) ;
ycord = zeros(3,1) ;
for d = 1:3
launchangle = input('Please input a Launch Angle between 1 and 90:')*(pi/180);
%Formula to calculate x velocity
velocityx = initialvel*cos(launchangle) ;
%Formula to calculate y velocity
velocityy = initialvel*sin(launchangle) ;
%Formula to calculate y-cordinate
ycord(d) = initialposy + velocityy * time - (1/2*gravity*(time^2)) ;
%Formula to calculate x-cordinate
xcord(d) = initialposx + velocityx * time ;
end
title('Angry Birds Knockoff Matlab Game');
plot(xcord,ycord, '--rs', 'linewidth', 2);

Catégories

En savoir plus sur Geoscience dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by