%	car.m

%	This program calculates the velocity of a car rolling down an incline 

%	under the influence of viscous friction.

%	The differential equation used to model the car is:

%

%		m dv/dt = m g sin(alpha) - b v

% 

%	This equation is stored in a separate m-file 'car_visc' called by this 

%	program (a tedious MATLAB detail).

%

%	Declare global parameters (a MATLAB detail).

%

global g alpha b m

%

%	Input parameter values.

%

g= 9.81;

m = input('Enter the mass of the car in SI units: ');

alpha = input('Enter the angle of the incline in degrees: ');

b = input('Enter the value of the friction coefficient "b" in SI units: ');

%

%	Input initial conditions.

%

v0 = input('Enter the initial velocity in SI units: ');

%

%	Input integration time.

%

tspan = input('Enter time interval of integration in seconds: ');

%

%	Call a numerical integration algorithm.

% 

[t,v] = ode45('car_visc', tspan, v0);

%

%	Plot the results.

%

plot(t,v)

xlabel('Time [seconds]')

ylabel('Speed, [meters/second]')

title('Speed of car on incline')

grid

%

%	Print out speed at final instant.

%

N = max(size(v));

Finalspeed = v(N)
