Incorrect Intersection Output of Two Lines

1 view (last 30 days)
Brianna
Brianna on 23 Nov 2020
Commented: Brianna on 29 Nov 2020
I have to represent a person (Klaus) jumping out of a plane, and then five seconds later a second person (Hans) jumps out of the plane with a parachute to catch the first person (Klaus). I can see on the plot where the two intersect, however, I am unable to output the position and value as an answer. I have tried using the intersect function and setting the two equations equal to eachother but neither have worked.
tklaus = (0:0.001:100)';
thans = (5:0.001:105)';
g = 9.81; % m/s/s
cd = 0.25; %kg/m
mk = 90.7185; %kg
mh = 113.398; %kg sum of mass of hans and parachute (before it is opened)
vk = @(tklaus) sqrt((g*mk)/cd) * tanh(sqrt((g*cd)/mk)*tklaus);
vh = @(thans) sqrt((g*mh)/cd) * tanh(sqrt((g*cd)/mh)*thans);
vklaus = vk(0:0.001:100)';
vhans = vh(0:0.001:100)';
xk = zeros(size(vklaus)); %xk is position of klaus in the vertical direction (m)
xk(1) = 4000; %jumps at 4000 m
xh = zeros(size(vhans)); %xh is position of hans in the vertical direction (m)
xh(1) = 4000; %jumps at 4000 m
% Plot to see acceleration plot
% plot(tklaus,vklaus,'b')
% hold on
% plot(thans,vhans,'r')
% hold on
% legend('klaus','hans')
% xlabel('time (seconds)')
% ylabel('velocity (meters/seconds)')
for i = 1:length(vklaus)-1
xk(i+1) = xk(i) - vklaus(i)*(tklaus(i+1)-tklaus(i));
end
for i = 1:length(vhans)-1
xh(i+1) = xh(i) - vhans(i)*(thans(i+1)-thans(i));
end
%Plot to see velocity plot
plot(tklaus,xk,'r')
hold on
plot(thans,xh,'b')
hold on
legend('klaus','hans')
xlabel('time (seconds)')
ylabel('height (meters)')

Answers (2)

Alan Stevens
Alan Stevens on 23 Nov 2020
After your two for loops put the following
intersectfn = @(t) interp1(tklaus,xk,t) - interp1(thans,xh,t);
t0 = 50; % Initial guess
tintersect = fzero(intersectfn,t0);
xintersect = interp1(tklaus,xk,tintersect);
disp([tintersect xintersect])
%Plot to see velocity plot
plot(tklaus,xk,'r',thans,xh,'b',tintersect,xintersect,'o'),grid
legend('klaus','hans')
xlabel('time (seconds)')
ylabel('height (meters)')

Jon
Jon on 23 Nov 2020
The main difficulty here is comparing Klaus and Hans heights at simultaneous times. Note that the elements of xh and xk are not at simultaneous times. So if we start a stop watch when Klaus jumps, then the time on the stop watch corresponding to the first element of xk is zero, but the first element of xh is 5. So we can't just take the two vectors of heights xh and xk and look element by element to see when they are very close (intersect) as they are not aligned in time.
One way to deal with this would be to rewrite your equations of motion to just use one common time, e.g. a stop watch that starts when Klaus jumps.
Another approach would be to use your data to interpolate values for Hans position at each value of Klaus time, so something like
xhInterp = interp1(thans,xh,tklaus); % interpolate values to Klaus time
plot(tklaus,xk,tklaus,xhinterp)
% define delta as the difference in the two jumpers position (using common time base)
delta = xk -xhInterp;
figure,
plot(tklaus,delta) % visualize the interception distance
xlabel('time')
ylabel('interception distance [m]')
% find where it the interception distance is closest to zero
% note delta will proably not be exactly zero at your time intervals, but you can approximate
% with closest approach
[deltamin,imin] = min(abs(delta))
tklaus(imin)
  2 Comments
Jon
Jon on 23 Nov 2020
It looks like you had already gotten an answer from Alan by the time I posted this. Actually both approaches have similar aspects, Alan's will give a more exact approximation as to the intercept time, but is a little more complicated.
Brianna
Brianna on 29 Nov 2020
Thank you for your response, I appreciate the help!

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!