Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
16 changed files
with
2,254 additions
and
2,253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a=[1 2 3]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Oops, something went wrong.