Point Mass model, Acceleration, Velocity and position using Euler approximation
Show older comments
Hi, I am really new in Matlab and I find myself a bit lost how to create the model I want.
I am trying to recreate an Acceleration event. my car has to accelerate from 0 to reach a distance of 75m
Then I want to plot the acceleration vs time, velocity and so on.
This is the basic code I use:
clear
clc
close all
%Constants for Point Mass
m=250 %kg
A=1.1 %m^2
C=1.91 %Drag Coefficient of the car
rho= 1.225 %kg/m^3 (density of air)
D=rho*C*A/2
g=9.81 %m/s^2 (acceleration due to gravity)
%Initial Conditions
dt= .001 %s
x(1)=0 %m
v0=0 %m/s
v=v0
t(1)=0
%Start Loop
i=1
while min(x)< 75;
a=-(D/m)*v^2;
v=v+a*dt;
x(i+1)=x(i)+v*dt+.5*a*dt^2;
t(i+1)=t(i)+dt;
i=i+1;
x(1)=x(i);
end
plot(t,a)
xlabel('time (s)')
ylabel('acceleration')
title('acceleration')
It stays runnig forever and I can not see how I can fix it
Answers (1)
darova
on 14 Mar 2021
Here is the answer
x(1)=0 %m
while min(x)< 75;
min(x) is always 0
Categories
Find more on Vehicle Dynamics Blockset 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!