CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
calculuslab

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: calculuslab/Calculus_Lab
Path: blob/main/142-Labs/Lab 08 - Project - Koch Snowflakes and Fractals.ipynb
Views: 491
Kernel: SageMath 9.2

Lab 08 - Project - Koch Snowflakes and Fractals

Overview

The word "fractal" is often used in referring to any object that is recursively constructed so that it appears similar at all scales of magnification. The gif below demonstrates this property with the Koch snowflake.

KochUrl1

There are many examples of complex real-life phenomena, such as chaos, ferns, mountains, river networks, and biological growth that can be described and studied using fractals. In this lab and project, we will analyze and generate a classic fractal, the Kock snowflake, and its variations. While it is natural to use a computer to do recursive constructions, we will focus on applications of sequences and series in our study.

Sections 10.1 and 10.2

A Variation of the Koch Snowflake

In this lab, we will analyze a variation of the Koch snowflake and use sequences and series to determine formulas for the perimeter and area of our snowflake at its various levels of construction. First, we will start with a square with side length 1. Then, we will add smaller squares to each of its four sides in such a way that each smaller square takes up the middle third of each side of the original square. We then repeat this process again and again. The final snowflake is the limit of this construction. The first four levels of such a constrution are given below.

drawing

We will use SageMath to develop general formulas for the area and perimeter of the first five levels and then use these formulas to determine the perimeter and area of the "final" snowflake.

First, we will create lists to hold information about the snowflake at the various stages. We want these lists to contain 5 values each, so we will go ahead and create them with 5 elements.

Length = [0,0,0,0,0] Sides = [0,0,0,0,0] Area = [0,0,0,0,0] Perimeter = [0,0,0,0,0]

We begin with a side length of 1 and 4 sides. Also, we know that the area of the snowflake at Stage 0 is 121^2 and the perimeter is 4(1)4(1).

Length[0] = 1 Sides[0] = 4 Area[0] = Length[0]^2 Perimeter[0] = Length[0] * Sides[0]

Now, we consider how these values change as we move to the next Stage. From the picture, you can see that the side-lengths are all the same and that common value is 1/31/3, since our smaller square had side-length one third of the previous square. Also, we can see that each line segment from the previous stage became five line segments. This pattern continues as we iterate through the stages. Therefore, we can use the following for loop to determine the length of each side and the number of sides for the first 5 stages of the snowflake.

for i in range(1,5): Length[i] = 1/3 * Length[i-1] Sides[i] = 5 * Sides[i-1] print(Length) print(Sides)

Now that we know the length of a line segment and the number of sides, we can develop formulas for the perimeter and the area at the various stages. Recall that the perimeter of a shape is the sum of the sides lengths making up the shape. Therefore, to find the perimeter at the nthn^\text{th} stage, we simply multiply the length of the sides by the number of sides.

for i in range(1,5): Perimeter[i] = Length[i] * Sides[i] print(Perimeter)

The formula for area is a little more involved. Note that at each stage, we are adding more area to the area that was currently there in the previous stage. Therefore, to determine the area at stage ii, we need to add our new area to the previous area. To calculate the new area, we see that we are adding some number of identical squares to our current snowflake. Since we are adding a new square to each side of the previous snowflake, we know that the number of squares we are adding is Sides[i1][i-1]. The length of each side of these new squares is Length[i][i]. Therefore, the new area is Sides[i1][i-1]Length[i]2[i]^2.

for i in range(1,5): Area[i] = Area[i-1] + Sides[i-1]*Length[i]^2 print(Area)

Now that we have found the perimeter and area of the first five stages of the snowflake, we will create general formulas which will give us the perimeter and area of the nthn^\text{th} snowflake. We saw in our calculation of the perimeter at stage nn that Pn=LnSnP_n = L_n * S_n, where Pn,Ln,P_n, L_n, and SnS_n are the perimeter, side length, and number of sides at stage nn, respectively. Therefore, to determine a general formula for perimeter, we first need to find general formulas for the length of each side and the number of sides. Recall that the length of each side started at 1 and then was multiplied by 13\frac{1}{3} each iteration. Therefore, Ln=1(13)n=13n.L_n = 1 * \left(\frac{1}{3}\right)^n = \frac{1}{3^n}. The number of sides started out 44 and then was multiplied by 55 each iteration. Thus, Sn=45n.S_n = 4 * 5^n. It follows that Pn=LnSn=13n45n=4(53)n.P_n = L_n * S_n = \frac{1}{3^n} * 4 * 5^n = 4\left(\frac{5}{3}\right)^n. We create this sequence in SageMath and check that it agrees with our previous calculations for perimeter.

n = var('n') def P(n): return 4*(5/3)^n for i in range(0,5): print("Stage: %d" %i) print(Perimeter[i]) print(P(i)) print("")

Therefore, we see that our general formula for perimeter is correct. We can determine the perimeter of the "final" snowflake by determining if the sequence PnP_n converges or diverges.

limit(P(n),n=infinity)

Thus, the perimeter of the "final" flake is infinite.

Now, we get a formula for area. Recall that to find the area of the nthn^\text{th} snowflake, we started with the previous area and then added the new area. Therefore, to find a general formula we have to start with the original area of 1 and then repeatedly add this new area for each stage up to nn. We saw earlier that the formula for our new area is NAn=Sn1Ln2=45n1(13n)2=45(59)n,NA_n = S_{n-1} * L_n^2 = 4*5^{n-1} * \left(\frac{1}{3^n}\right)^2 = \frac{4}{5} * \left(\frac{5}{9}\right)^n, where NAnNA_n is the new area added at stage nn. Therefore, we have that An=A0+i=1nNAi=1+i=1n45(59)n,A_n = A_0 + \sum_{i = 1}^{n} NA_i = 1 + \sum_{i=1}^n \frac{4}{5} \left(\frac{5}{9}\right)^n, where AnA_n is the total area at stage nn. Again, we compare this formula to our previous calculations for area.

i = var('i') def A(n): return 1 + sum(4/5 * (5/9)^i, i, 1, n) for k in range(0,5): print("Stage: %d" %k) print(Area[k]) print(A(k)) print("")

Therefore, our formula is correct. Now, we will use SageMath to determine the area of the "final" snowflake.

limit(A(n),n=infinity)

Thus, the "final" snowflake has finite area of 2 but infinite perimeter.

Project

Write a report analyzing the two types of fractals given below. Your report should follow the guidelines set forth in the Project Report Guidelines on the lab website and is due by the date specified by your TA.

Consider the original Koch snowflake and a variation given below.

drawing

drawing

For each of the two snowflakes, you should:

  1. Present details to show that you fully understand the given flake construction.

  2. Find the area and the perimeter up to Level 4.

  3. Develop general formulas for the perimeter and area

  4. Use SageMath to discover the perimeter and the area of the "final" snowflake.

  5. Have a discussion on what you have learned, such as some of the interesting properties of the snowflakes and how your knowledge of sequences and series aided your evalutation.