Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Problem 255. Spiraling out of control....

Created by Matt Fig

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.

Tags

Problem Group

Solution Statistics

30 correct solutions 51 incorrect solutions
Last solution submitted on Feb 21, 2014

Problem Comments

Solution Comments