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.
I can solve the simpler test cases, but how do you handle the eps stuff without too much error or crashing the program?
any suggestions for handling my error?
I see what you are trying to do, but there is an analytical solution for L. It seems you only have a problem with L, not p (as far as the test cases).
I'll take another look
Octogenarian, Shmoctogenarian! Hope that one didn't keep you up too late, Roger. :-)
I feel like there should be an analytical solution for L, but it's too late at night to do any non-computational numerical analysis of this sequence.
2162 Solvers
8 Solvers
35 Solvers
Return a list sorted by number of consecutive occurrences
103 Solvers
Create logical matrix with a specific row and column sums
99 Solvers