Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
01_ME3255_repo/Problem 5
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
28 lines (24 sloc)
1.01 KB
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
%Problem 5 | |
%Part A creates a chart illustrating free fall velocity calculated analytically and numerically | |
function[v_analytical,v_terminal,t] = freefalls(h,timespan) | |
t = (0:h:timespan) %creates time intervals size h between zero and timespan | |
c = 0.25 %define vars | |
m = 60 %define vars | |
g = 9.81 %define vars | |
v_terminal = sqrt(m*g/c); | |
v_analytical = v_terminal*tanh(g*t/v_terminal); | |
v_numerical = zeros(length(t),1); | |
deltat = diff(t) | |
for i = 1:length(t)-1 | |
v_numerical(i+1) = v_numerical(i)+(g-c/m*v_numerical(i)^2)*deltat(i); | |
end | |
indices = round(linspace(1,length(t),7)); | |
fprintf('time (s)|vel analytical (m/s)|vel numerical(m/s)\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,'0-') | |
%Part B Runs the comparison | |
freefalls(.1,30); hold on | |
freefalls(1,30); hold on | |
freefalls(5,30; hold off | |
legend('h=.1 - Analytical','h=.1 - Numerical','h=1 - Analytical','h=1 - Numerical','h=5 - Analytical','h=5 - Numerical','Location','Northwest') | |