Problem 7.8 part ( C )
Nasser Abbasi
Output
»
nma_7_8_partc
plot trajectories of xc(t) for problem 7.8,
part b
Nasser Abbasi
Source code
%
% plot position with time for car
for problem 7.8, part c
% Nasser Abbasi
%
clear all; help nma_7_8_partc;
Vm = 1;
XcV =[-1 -2 -3 -4 -5 -6 -7 -8 -9 -10]; % some
values for Xc(0)
n=0;
for(k=1:length(XcV))
Xc =
XcV(k);
time=0;
currentPosition= Xc;
while(currentPosition <= 0 )
time =
time + 0.01;
if( time < - Xc/Vm )
currentPosition = Xc; % i.e. remain
standing still
else
currentPosition= Vm*time - 2* real(sqrt(-Xc*Vm*time));
end
end
n=n+1;
x(n,1) =
time;
x(n,2) =
Xc;
end
plot(x(:,1),abs(x(:,2)));
title('time it takes
to reach intersection for different Xc(0), Vm=1');
xlabel('time');
ylabel('Xc(0)');