Bike model with and without air resistance using matlab

1 次查看(过去 30 天)
Hi I'm trying to follow along in a computational physics book (Computational Physics; Nicholas Giordano 2nd edition) that attempts to model a bike with and without air resistance. I did everything that the book did but I got a completely different plot at the end.This is my code for the bike with air resistance.
function bike(v0,dt,tf)
t = 0:dt:tf;
v(1) = v0;
P = 400;
m = 70;
p = 1.225
A = 0.33
for i = 1:length(t)-1
v(i+1) = v(i) + (P/m*v(i)-(p*A*v(i)^2/2*m))*dt;
t(i+1) = t(i) + dt;
end
plot(t,v,'b');
title('Comparison of Euler approximation to actual solution')
xlabel('time')
ylabel('v')
disp(v(end));
P stands for power, m is mass, p is density of air, and A is the frontal area of the rider.
This is my code for the bike without air resistance.
function bike(v0,dt,tf)
t = 0:dt:tf;
v(1) = v0;
P = 400;
m = 70;
for i = 1:length(t)-1
v(i+1) = v(i) + (P/m*v(i))*dt;
t(i+1) = t(i) + dt;
end
plot(t,v,'b');
title('Comparison of Euler approximation to actual solution')
xlabel('time')
ylabel('v')
disp(v(end));
If someone could please help me out, I would really appreciate it.

采纳的回答

pfb
pfb 2015-4-11
The dimensions in your formulas do not look right. I think it is a matter of operator precedence. 1/2*3 is not the same as 1/(2*3).
Also, note that you build the time vector twice: once at the beginning
t = 0:dt:tf
and then in the loop
t(i+1) = t(i) + dt;
However this should be no problem.

更多回答(1 个)

göker akdag
göker akdag 2019-3-4
salak

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by