-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbhavsa2_lab07.m
43 lines (33 loc) · 996 Bytes
/
dbhavsa2_lab07.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
clear
clc
close all
%Instantiate constants and variables
g = 9.8;
theta = 60;
vi = 35;
ti = 0;
%Calculate components
vix = vi*cosd(theta);
viy = (vi*sind(theta)) - (g*ti);
%Store in an array and output
v = [vix, viy]
%Compute trajectory
%Calculate how long object will be in flight
tmax = (2*vi*sind(theta))/g;
%Create an evenly spaced vector of 250 time points between t = 0 and t = tmax
timePoints = linspace(ti, tmax, 250);
%Create vectors for x and y displacement at each time point
xdisp = linspace(ti, tmax, 250);
ydisp = linspace(ti, tmax, 250);
n = 1;
while n <= length(xdisp) %Fill all values until 250 displacement values in each dimension
xdisp(n) = vi*timePoints(n)*cosd(theta);
ydisp(n) = (vi*timePoints(n)*sind(theta))-(0.5*g*(timePoints(n)^2));
n = n + 1;
end
%Plot out graph of motion
figure('Name','Projectile Motion')
plot(xdisp, ydisp);
title ("Projectile Motion");
xlabel ("x distance");
ylabel ("y distance");