how can i improve this code to bacame better more
Show older comments
% matlab program for solving the bungee jumber problem using Eulers method
g=9.81;
m=80;
cd=0.25;
t0=0;
tend=20;
dt=0.5;
vi=0;
t=t0:dt:tend;
% the analytic solution
vel=sqrt(g*m/cd)*tanh(sqrt(g*cd/m)*t);
% the numrical solution
for ti=0:2:20
v1=vi+(g-cd/m*vi.^2).*((ti+2)-ti)
v2=v1+(g-cd/m*v1.^2).*((ti+2)-ti)
v3=v2+(g-cd/m*v2.^2).*((ti+2)-ti)
v4=v3+(g-cd/m*v3.^2).*((ti+2)-ti)
v5=v4+(g-cd/m*v4.^2).*((ti+2)-ti)
v6=v5+(g-cd/m*v5.^2).*((ti+2)-ti)
v7=v6+(g-cd/m*v6.^2).*((ti+2)-ti)
v8=v7+(g-cd/m*v7.^2).*((ti+2)-ti)
v9=v8+(g-cd/m*v8.^2).*((ti+2)-ti)
v10=v9+(c-cd/m*v9.^2).*((ti+2)-ti)
end
tt=[2 4 6 8 10 12 14 16 18 20]
v=[v1 v2 v3 v4 v5 v6 v7 v8 v9 v10]
% plotting of results
plot(t,vel)
hold on
plot(tt,v,'r')
grid
xlabel('time (s)')
ylabel('velocity (m/s)')
title('vilocity for the bungee jumber')
legend('analytical','numerical')
Accepted Answer
More Answers (0)
Categories
Find more on Simulink Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!