Effacer les filtres
Effacer les filtres

Help finding when the object is closest to the origin

7 vues (au cours des 30 derniers jours)
Steven
Steven le 1 Avr 2012
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.

Réponses (3)

Walter Roberson
Walter Roberson le 1 Avr 2012
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 commentaires
Walter Roberson
Walter Roberson le 1 Avr 2012
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.
Steven
Steven le 1 Avr 2012
where did you come up with the equation for the time? I understand how to get distance but I dont understand the time

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 1 Avr 2012
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 commentaires
Jacob
Jacob le 18 Mar 2014
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
Image Analyst le 18 Mar 2014
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);

Connectez-vous pour commenter.


Sean de Wolski
Sean de Wolski le 18 Mar 2014
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

Community Treasure Hunt

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

Start Hunting!

Translated by