You are on page 1of 6

1.

a.
clear all
clc
% Set the values for initial speed, gravity, and angle.
v0 = 40; g = 9.81; A=30*pi/180;
% Compute the time to hit.
t_hit = 2*v0*sin(A)/g;
% Comput the arrays containing time, height, and speed.
t = [0 : t_hit/100 : t_hit];
h = v0*t*sin(A) - 0.5*g*t.^2;
h15=15*t.^0;
plot(t,h,t,h15,'Linewidth',2)
set(gca,'LineWidth',2,'FontSize',12)
xlabel('\bf Time','FontSize',12)
ylabel('\bf Height','FontSize',12)
% Determine when the height is no less than 15
y = h>=15
u = find( y ); % u = find(h>=15);
% Compute the corresponding times.
t_1 = (u(1)-1)*(t_hit/100)
t_2 = u(length(u)-1)*(t_hit/100)
==============================================================

t_1=1.0194
t_2=3.0581

b.
clear all
clc
% Set the values for initial speed, gravity, and angle.
v0 = 40; g = 9.81; A=30*pi/180;
% Compute the time to hit.
t_hit = 2*v0*sin(A)/g;
% Comput the arrays containing time, height, and speed.
t = [0 : t_hit/100 : t_hit];
h = v0*t*sin(A) - 0.5*g*t.^2;
v = sqrt(v0^2 - 2*v0*g*sin(A)*t + g^2*t.^2);
h15=15*t.^0; v36=36*t.^0;
subplot(3,1,1)
plot(t,h,t,h15,'Linewidth',2)
set(gca,'LineWidth',2,'FontSize',12)
xlabel('\bf Time','FontSize',12)
ylabel('\bf Height','FontSize',12)
subplot(3,1,2)
plot(t,v,t,v36,'Linewidth',2)
set(gca,'LineWidth',2,'FontSize',12)
xlabel('\bf Time','FontSize',12)
ylabel('\bf Velocity','FontSize',12)
% Determine when the height is no less than 15,
% and the speed is no greater than 36.
y = h>=15 & v<=36;
u = find( y ); % u = find( h>=15 & v<=36 );
subplot(3,1,3)
plot(t,y,'o','MarkerSize',4)
set(gca,'LineWidth',2,'FontSize',12)
xlabel('\bf Time','FontSize',12)
ylabel('\bf T (1) or F (0)','FontSize',12)
% Compute the corresponding times.
t_1 = (u(1)-1)*(t_hit/100)
t_2 = u(length(u)-1)*(t_hit/100)
=========================================================

t_1=1.0601
t_2=3.0173

c.
clear all
clc
% Set the values for initial speed, gravity, and angle.
v0 = 40; g = 9.81; A=30*pi/180;
% Compute the time to hit.
t_hit = 2*v0*sin(A)/g;
% Comput the arrays containing time, height, and speed.
t = [0 : t_hit/100 : t_hit];
h = v0*t*sin(A) - 0.5*g*t.^2;
v = sqrt(v0^2 - 2*v0*g*sin(A)*t + g^2*t.^2);
h5=5*t.^0; v35=35*t.^0;
subplot(3,1,1)
plot(t,h,t,h5,'Linewidth',2)
set(gca,'LineWidth',2,'FontSize',12)
xlabel('\bf Time','FontSize',12)
ylabel('\bf Height','FontSize',12)
subplot(3,1,2)
plot(t,v,t,v35,'Linewidth',2)
set(gca,'LineWidth',2,'FontSize',12)
xlabel('\bf Time','FontSize',12)
ylabel('\bf Velocity','FontSize',12)
% Determine when the height is less than 5,
% and the speed is greater than 35.
y = h<5 | v>35;
u = find( y ); % u = find( h<5 & v>35 );
subplot(3,1,3)
plot(t,y,'o','MarkerSize',4)
set(gca,'LineWidth',2,'FontSize',12)
xlabel('\bf Time','FontSize',12)
ylabel('\bf T (1) or F (0)','FontSize',12)
subplot(3,1,3)
plot(t,y,'o','MarkerSize',4)
set(gca,'LineWidth',2,'FontSize',12)
xlabel('\bf Time','FontSize',12)
ylabel('\bf T (1) or F (0)','FontSize',12)
% Compute the corresponding times.
y1 = (h<5 | v>35) & t<=t_hit/2;
u = find( y1 ); % u = find( h<5 & v>35 );
t_1 = (u(1)-1)*(t_hit/100)
t_2 = u(length(u)-1)*(t_hit/100)
y2 = (h<5 | v>35) & t>=t_hit/2;
u = find( y2 );
t_3 = (u(1)-1)*(t_hit/100)
t_4 = u(length(u)-1)*(t_hit/100)
=========================================================


t_1=0
t_2=1.5087
t_3=2.5688
t_4=4.0775
0~1.5087and2.5688~4.0775

2
a.
functionfile:spring.m
function x = spring(W,k1,k2,d);
s = W / k1;
if s < d
x = W / k1;
else
x = (W + 2*k2*d) / (k1 + 2*k2);
end

mainprogram
clear all
clc
k1 = 10000;
k2 = 15000;
d = 0.1;
W1 = 500;
W2 = 2000;
x1 = spring(W1,k1,k2,d)
x2 = spring(W2,k1,k2,d)
x1 = 0.0500
x2 = 0.1250
b.
clear all
clc
k1 = 10000;
k2 = 15000;
d = 0.1;
W1 = 500;
W2 = 2000;
for W = 0:3000
x = spring(W,k1,k2,d);
plot(W,x)
hold on
end
xlabel(' W','FontSize',14)
ylabel(' x','FontSize',14)
=========================================================

You might also like