How do you construct rectangular figures using the Fibonacci numbers in Mathematica using graphics? I know that the basis of the construction of these figures are the formulae for summing the terms, the odd-indexed terms, the even-indexed terms and the sum of the squares of the terms. I'm really confused on how to obtain the rectangular figures.

New contributor
user503154 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

you mean something like this?

Graphics[{Red, Rectangle[{0, 0}, {Fibonacci@6, Fibonacci@5}], Green, 
Rectangle[{0, 0}, {Fibonacci@4, Fibonacci@5}], Yellow, 
Rectangle[{0, 0}, {Fibonacci@4, Fibonacci@3}], Blue, 
Rectangle[{0, 0}, {Fibonacci@2, Fibonacci@3}], Pink, 
Rectangle[{0, 0}, {Fibonacci@2, Fibonacci@1}]}]    

enter image description here

but if you want the real thing, here you are..

gr[0] := {{0, 0}, {1, -1}};
gr[n_] := 
Module[{\[Phi] = GoldenRatio, m = Mod[n, 4], a, b, c, 
d}, {{a, b}, {c, d}} = gr[n - 1];
Switch[Mod[n, 4], 0, {{a, d}, {a + \[Phi]^-n, d - \[Phi]^-n}}, 
1, {{c, d + \[Phi]^-n}, {c + \[Phi]^-n, d}}, 
2, {{c - \[Phi]^-n, b + \[Phi]^-n}, {c, b}}, 
3, {{a - \[Phi]^-n, b}, {a, b - \[Phi]^-n}}]];
Graphics[{EdgeForm[Opacity[.5]],Table[{ColorData[24, k + 1], Rectangle @@gr[k]}, {k, 0, 10}]}]

enter image description here

  • 2
    Please don't use JPG for non-photographic images! :) If you look at the edges of your squares, especially at the bottoms of your images, you see strange stripes. This is caused by using JPG (a compressed format designed to be used with photographs) for something that very much isn't a photograph! PNG is the preferred format for illustrations, screenshots, diagrams, etc. (basically any image that isn't a photograph, especially if it contains large, solid-colour regions, text, or discrete curves). – Andreas Rejbrand Oct 12 at 5:41

NestList[] is very handy for situations like this:

tr[Polygon[p_]] := Polygon[Composition[TranslationTransform[First[p]],
   AffineTransform[{{0, -1}, {1, 0}}/GoldenRatio], TranslationTransform[-Last[p]]] @ p]

g1 = Graphics[{EdgeForm[Black], MapIndexed[{ColorData[61] @@ #2, #1} &, 
    NestList[tr, Polygon[{{GoldenRatio, 0}, {GoldenRatio, 1}, {0, 1}, {0, 0}} // N], 10]]}]


If you want to see the accompanying golden spiral as well:

tr[Circle[c_, r_, ang_]] := Circle[c + r AngleVector[Last[ang]]/(1 + GoldenRatio), r/GoldenRatio, ang + π/2]

Show[g1, Graphics[{Gray, NestList[tr, Circle[{1, 1}, 1, {π, 3 π/2}], 10]}]]

enter image description here

Your Answer

user503154 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.