필터 지우기
필터 지우기

Bike model with and without air resistance using matlab

조회 수: 1 (최근 30일)
Mohamed Saeed
Mohamed Saeed 2015년 4월 11일
답변: göker akdag 2019년 3월 4일
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