Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
blah
  • Loading branch information
Braisted committed Sep 14, 2017
1 parent 708dca7 commit f5d25ae
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 2,794 deletions.
File renamed without changes.
Binary file renamed Problem 3/Thumbs.db → Problem 5/Thumbs.db
Binary file not shown.
File renamed without changes
46 changes: 23 additions & 23 deletions Problem 3/freefall.m → Problem 5/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 → Problem 5/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
34 changes: 17 additions & 17 deletions Problem 3/freefall_comparison.m → Problem 5/freefall_comparison.m
@@ -1,17 +1,17 @@
g=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')

saveas(g,'figure01.png')
g=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')

saveas(g,'figure01.png')
54 changes: 27 additions & 27 deletions Problem 5/my_acceleration.m → Problem 6/my_acceleration.m
@@ -1,27 +1,27 @@
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);
%added apostrophe for derivatives of velocity

end
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);
%added apostrophe for derivatives of velocity

end
54 changes: 27 additions & 27 deletions Problem 5/my_velocity.m → Problem 6/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

70 changes: 0 additions & 70 deletions US_energy_by_sector.csv

This file was deleted.

0 comments on commit f5d25ae

Please sign in to comment.