MATLAB Answers

Incorrect Intersection Output of Two Lines

조회 수: 1(최근 30일)
Brianna
Brianna 2020년 11월 23일
댓글: Brianna 2020년 11월 29일
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)')

답변(2개)

Alan Stevens
Alan Stevens 2020년 11월 23일
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)')
  댓글 수: 1
Brianna
Brianna 2020년 11월 29일
Thank you for your response, I appreciate the help!

댓글을 달려면 로그인하십시오.


Jon
Jon 2020년 11월 23일
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
Brianna
Brianna 2020년 11월 29일
Thank you for your response, I appreciate the help!

댓글을 달려면 로그인하십시오.

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by