Help finding when the object is closest to the origin
조회 수: 7 (최근 30일)
이전 댓글 표시
I need help writing a program to determine the time the object is closest to the origin (0,0). I also have to determine the minimum distance.
The x,y coordinates are given as follows:
x(t)=5t-10 & y(t)=25t^2-120t+144
How would I find it. I've tried really hard and can't figure it out. I need to find it by:
a) using a for loop
b)without using a for loop
It would be so grateful if someone could help me.
댓글 수: 0
답변 (3개)
Walter Roberson
2012년 4월 1일
The time of closest approach is an irrational number, so you will not be able to find it through a numeric solution.
There is a way to use a "for" loop to solve it symbolically, but the "for" loop would have such a minor role that it would not be worth mentioning in the problem description.
댓글 수: 5
Walter Roberson
2012년 4월 1일
You will not be able to construct a numeric solution to this problem. The time of the minimum approach is
(1/30)*(-(108+6*sqrt(330))^(2/3)+6+72*(108+6*sqrt(330))^(1/3))/(108+6*sqrt(330))^(1/3)
which is an irrational number and so is infinitely long and so cannot be represented in finite length in any "based" number system that uses only rational number bases.
The closest you would be able to get with a numeric solution is the IEEE 754 Double Precision number which most closely approximates the irrational time of closest approach. That finite double precision number will, however, *not* be the time of closest approach, merely an approximation to that time. Your statement of the problem requires the time of closest approach, not an _approximation_ of that time.
Image Analyst
2012년 4월 1일
Perhaps this hint will help you. It plots the data (without for loop) so you can see what's going on.
% Create t axis.
t= (0:0.1:3)';
% Get parameterized version of x and y.
x=5*t-10;
y=25*t.^2-120*t+144;
% Calculate distance of (x,y) from (0,0)
distanceFromOrigin = sqrt(x.^2 + y.^2);
% Plot the curves.
subplot(1, 2, 1);
plot(x,y, 'bo-');
axis equal;
grid on;
fontSize = 20;
% xlim([-10 10]);
xlabel('x', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
title('x vs. y, with time=0 at the left edge of the graph', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
subplot(1, 2, 2);
plot(t, distanceFromOrigin, 'bo-');
grid on;
xlabel('t', 'FontSize', fontSize);
ylabel('Distance', 'FontSize', fontSize);
title('Distance from (0,0) vs. time', 'FontSize', fontSize);
% Now calculate the mins.
댓글 수: 8
Jacob
2014년 3월 18일
I understand how to calculate this with the for loop, however am confused on how to do this without the for loop? help?
Image Analyst
2014년 3월 18일
You have the min distance:
distanceFromOrigin = sqrt(x.^2 + y.^2);
This is an array so find the min value and location
[minDistance, indexOfMin] = min(distanceFromOrigin);
Now get the time at that index. The index where the min distance occurs will be the same for x, y, and t.
timeAtTheMinDistance = t(indexOfMin);
Sean de Wolski
2014년 3월 18일
You could use one of the optimization functions to find the minimum time. For example:
fx = @(t)5*t-10;
fy = @(t)25*(t.^2)-(120*t)+144;
tmin = 0;
tmax = 10;
[x,fval] = fmincon(@(t)hypot(fx(t),fy(t)),5,[],[],[],[],tmin,tmax)
Yields
x =
2.2330
fval =
1.3577
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Number Theory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!