MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

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.

39 correct solutions
51 incorrect solutions

Last solution submitted on Mar 16, 2015

1 Comment

Matt Fig
on 5 Feb 2012

Octogenarian, Shmoctogenarian! Hope that one didn't keep you up too late, Roger. :-)

1 Comment

@bmtran
on 5 Feb 2012

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.

1 Comment