Plotting Velocity-Time Curve for multiple angles.

15 Ansichten (letzte 30 Tage)
Callum Ogilvie
Callum Ogilvie am 3 Apr. 2017
Beantwortet: KSSV am 4 Apr. 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

Antworten (1)

KSSV
KSSV am 4 Apr. 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);

Kategorien

Mehr zu Geoscience finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by