Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
No commit message
  • Loading branch information
teb11007 authored and teb11007 committed Sep 14, 2017
1 parent 19ed571 commit 31c7b64
Show file tree
Hide file tree
Showing 16 changed files with 2,254 additions and 2,253 deletions.
1 change: 1 addition & 0 deletions A_66.m
@@ -0,0 +1 @@
a=[1 2 3];
46 changes: 23 additions & 23 deletions Problem 3/freefall.m
@@ -1,23 +1,23 @@
function [v_analytical,v_terminal,t]=freefall(h,timespan)
% help file for freefall.m
% N is number of timesteps between 0 and 12 sec
% v_an...
N=timespan/h+1;
t=linspace(0,timespan,N)';
c=0.25; m=60; g=9.81; v_terminal=sqrt(m*g/c);

v_analytical = v_terminal*tanh(g*t/v_terminal);
v_numerical=zeros(length(t),1);
delta_time =diff(t);
for i=1:length(t)-1
v_numerical(i+1)=v_numerical(i)+(g-c/m*v_numerical(i)^2)*delta_time(i);
end
% Print values near 0,2,4,6,8,10,12 seconds
indices = round(linspace(1,length(t),7));
fprintf('time (s)|vel analytical (m/s)|vel numerical (m/s)\n')
fprintf('-----------------------------------------------\n')
M=[t(indices),v_analytical(indices),v_numerical(indices)];
fprintf('%7.1f | %18.2f | %15.2f\n',M(:,1:3)');
plot(t,v_analytical,'-',t,v_numerical,'o-')
end

function [v_analytical,v_terminal,t]=freefall(h,timespan)
% help file for freefall.m
% N is number of timesteps between 0 and 12 sec
% v_an...
N=timespan/h+1;
t=linspace(0,timespan,N)';
c=0.25; m=60; g=9.81; v_terminal=sqrt(m*g/c);

v_analytical = v_terminal*tanh(g*t/v_terminal);
v_numerical=zeros(length(t),1);
delta_time =diff(t);
for i=1:length(t)-1
v_numerical(i+1)=v_numerical(i)+(g-c/m*v_numerical(i)^2)*delta_time(i);
end
% Print values near 0,2,4,6,8,10,12 seconds
indices = round(linspace(1,length(t),7));
fprintf('time (s)|vel analytical (m/s)|vel numerical (m/s)\n')
fprintf('-----------------------------------------------\n')
M=[t(indices),v_analytical(indices),v_numerical(indices)];
fprintf('%7.1f | %18.2f | %15.2f\n',M(:,1:3)');
plot(t,v_analytical,'-',t,v_numerical,'o-')
end

12 changes: 6 additions & 6 deletions Problem 3/freefall_2.m
@@ -1,6 +1,6 @@
figure
hold on
timespan=30;
for h=[.1,1,5]
freefall(h,timespan)
end
figure
hold on
timespan=30;
for h=[.1,1,5]
freefall(h,timespan)
end
32 changes: 16 additions & 16 deletions Problem 3/freefall_comparison.m
@@ -1,16 +1,16 @@
figure
hold on
timespan=30;

for h=[.1,1,5]
freefall(h,timespan)
end
set(0, 'defaultAxesFontSize', 16)
set(0,'defaultTextFontSize',14)
set(0,'defaultLineLineWidth',3)
set(gcf, 'Position', [200, 200, 1000, 800])
xlabel('Time (seconds)')
ylabel('Velocity (meters/second)')
legend('v analytical(0.1)','v numerical(0.1)','v analytical(1)','v numerical(1)','v analytical(5)','v numerical(5)','Location','southeast')
title('Velocity Comparison by Varying Time Steps')

figure
hold on
timespan=30;

for h=[.1,1,5]
freefall(h,timespan)
end
set(0, 'defaultAxesFontSize', 16)
set(0,'defaultTextFontSize',14)
set(0,'defaultLineLineWidth',3)
set(gcf, 'Position', [200, 200, 1000, 800])
xlabel('Time (seconds)')
ylabel('Velocity (meters/second)')
legend('v analytical(0.1)','v numerical(0.1)','v analytical(1)','v numerical(1)','v analytical(5)','v numerical(5)','Location','southeast')
title('Velocity Comparison by Varying Time Steps')

50 changes: 25 additions & 25 deletions Problem 5/my_acceleration.m
@@ -1,26 +1,26 @@
function [ax,ay,az]=my_acceleration(x,y,z,t)
% Help documentation of "my_acceleration"
% This function computes the acceleration in the x- and y-directions given
% three vectors of position in x- and y-directions as a function of time
% x = x-position
% y = y-position
% z = z-position
% t = time
% output
% ax = acceleration in x-direction
% ay = acceleration in y-direction
% az = acceleration in z-direction

function v=diff_match_dims(x,t)
v=zeros(length(t),1);
v(1:end-1)=diff(x)./diff(t);
v(end)=v(end-1);
end

[vx,vy,vz]=my_velocity(x,y,z,t);

ax = diff_match_dims(vx,t);
ay = diff_match_dims(vy,t);
az = diff_match_dims(vz,t);

function [ax,ay,az]=my_acceleration(x,y,z,t)
% Help documentation of "my_acceleration"
% This function computes the acceleration in the x- and y-directions given
% three vectors of position in x- and y-directions as a function of time
% x = x-position
% y = y-position
% z = z-position
% t = time
% output
% ax = acceleration in x-direction
% ay = acceleration in y-direction
% az = acceleration in z-direction

function v=diff_match_dims(x,t)
v=zeros(length(t),1);
v(1:end-1)=diff(x)./diff(t);
v(end)=v(end-1);
end

[vx,vy,vz]=my_velocity(x,y,z,t);

ax = diff_match_dims(vx,t);
ay = diff_match_dims(vy,t);
az = diff_match_dims(vz,t);

end
54 changes: 27 additions & 27 deletions Problem 5/my_velocity.m
@@ -1,27 +1,27 @@
function [vx,vy,vz] = my_velocity(x,y,z,t)
% Help documentation of "my_velocity"
% This function computes the velocity in the x- and y-directions given
% three vectors of position in x- and y-directions as a function of time
% x = x-position
% y = y-position
% z = z-position
% t = time
% output
% vx = velocity in x-direction
% vy = velocity in y-direction
% vz = velocity in z-direction

vx=zeros(length(t),1);
vy=zeros(length(t),1);
vz=zeros(length(t),1);

vx(1:end-1) = diff(x)./diff(t); % calculate vx as delta x/delta t
vy(1:end-1) = diff(y)./diff(t); % calculate vy as delta y/delta t
vz(1:end-1) = diff(z)./diff(t); % calculate vy as delta y/delta t

vx(end) = vx(end-1);
vy(end) = vy(end-1);
vz(end) = vz(end-1);

end

function [vx,vy,vz] = my_velocity(x,y,z,t)
% Help documentation of "my_velocity"
% This function computes the velocity in the x- and y-directions given
% three vectors of position in x- and y-directions as a function of time
% x = x-position
% y = y-position
% z = z-position
% t = time
% output
% vx = velocity in x-direction
% vy = velocity in y-direction
% vz = velocity in z-direction

vx=zeros(length(t),1);
vy=zeros(length(t),1);
vz=zeros(length(t),1);

vx(1:end-1) = diff(x)./diff(t); % calculate vx as delta x/delta t
vy(1:end-1) = diff(y)./diff(t); % calculate vy as delta y/delta t
vz(1:end-1) = diff(z)./diff(t); % calculate vy as delta y/delta t

vx(end) = vx(end-1);
vy(end) = vy(end-1);
vz(end) = vz(end-1);

end

8 changes: 4 additions & 4 deletions README.md
@@ -1,4 +1,4 @@
# 01_ME3255_repo

# Answer to Homework Question
I hope to learn how to perform MATLAB functions more easily.
# 01_ME3255_repo

# Answer to Homework Question
I hope to learn how to perform MATLAB functions more easily.
10 changes: 5 additions & 5 deletions Set_Defaults.m
@@ -1,5 +1,5 @@
% Set defaults for plotting in Matlab.

set(0,'defaultAxesFontSize',18)
set(0,'defaultTextFontSize',18)
set(0,'defaultLineLineWidth',4)
% Set defaults for plotting in Matlab.

set(0,'defaultAxesFontSize',18)
set(0,'defaultTextFontSize',18)
set(0,'defaultLineLineWidth',4)

0 comments on commit 31c7b64

Please sign in to comment.