Problem 255. Spiraling out of control....
Imagine a square with corners at the origin and at (1,1). An interesting spiral can be created by tracing the path of a moving point that starts at the origin and intersects the leftmost opposite edge at a point (F,1), where F is the fraction of the length of the intersected edge. The point then continues on in this way, always heading for the leftmost opposite side of its path and intersecting the segment at a point which is fraction F of its length. For example, if F = 1/2, the first few points are:
P = [0 0;0.5 1;1 0.5;0.5 0;0.25 0.5;.75 .75]; plot(P(:,1),P(:,2),'*') axis equal
If F = 1/3, then the first few positions of the particle are:
P = [0 0;1/3 1;1 2/3;2/3 0;1/9 1/3;5/9 8/9];
Write a function that takes two inputs and returns two outputs. The first input argument, N, is the Nth location of the particle. The second input argument is the fraction F, where F is on (0,1). The first returned argument is a two element row vector that has the coordinates of the Nth location of the particle as [x,y]. The second returned argument is the limiting value of the particles location as N>infinity. For example,
[P,L] = my_spiral(3,1/2)
returns
P = [1 0.5]
and
L = [?x? ?y?]
Where both values of L are doubles accurate to 100*eps.
Solution Stats
Problem Comments

2 Comments
I can solve the simpler test cases, but how do you handle the eps stuff without too much error or crashing the program?
good question
Solution Comments
Show commentsProblem Recent Solvers11
Suggested Problems

2040 Solvers

Find common elements in matrix rows
2628 Solvers

349 Solvers

What is the distance from point P(x,y) to the line Ax + By + C = 0?
370 Solvers

8847 Solvers
More from this Author6
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!