Filter löschen
Filter löschen

Bike model with and without air resistance using matlab

1 Ansicht (letzte 30 Tage)
Mohamed Saeed
Mohamed Saeed am 11 Apr. 2015
Beantwortet: göker akdag am 4 Mär. 2019
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.

Akzeptierte Antwort

pfb
pfb am 11 Apr. 2015
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.

Weitere Antworten (1)

göker akdag
göker akdag am 4 Mär. 2019
salak

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by