Car Simulation Program



Hello,

Can anyone please help me with the following program?

function [retv rets retx]=compute_car(F, wt, rho, theta1, delta_t, t)
%
% COMPUTE_CAR(F, WT, RHO, THETA, DELTA_T, T)
%
% This function computes the velocity and displacement of a car as it
goes
% up an incline given force of engine(F), weight of car(wt),
coefficient of
% friction(rho), angle of slope(theta1), time interval(delta_t) and
% time(t).
%
% Example Usage:
%
% [retv rets retx] = compute_car(500, 4000, 1.14, 0.1,30)
%
%
% Set initial conditions s(1) = 0, v(1) = 0, starting time t(1)= 0.0

n=t/delta_t;

v=[1:n];
s=[1:n];
x=[1:n];

v(1)=0;
s(1)=0; % The current distance traveled
x(1)=0;
% We need an index i. Since s(1), v(1) and time(1) are initialized, we
will start i=2
i=2;

% Some constant
g = 9.81; %gravity

theta = car_angle(theta1);

for i=2:n

% Compute velocity v(i)
v(i)=v(i-1) + ((F/wt) - g*sin(theta) - rho*g*v(i-1))*delta_t

% Compute distance traveled s(i)
s(i) = s(i-1) + v(i)*delta_t

% Time

x(i)=x(i-1)+delta_t

end

retv=v;
rets=s;
retx=x;
%
% Sub-functions.
%

function theta = car_angle(theta1)
%
%
% Find the angle of the slope in radians.
%
% Convert angle to radians.
theta = theta1 * pi / 180;

.



Relevant Pages