Applied Mathematics Mam1044H sunflower and fractal project

16
Applied Mathematics MAM1044/MAM1043H Chlo´ e Sole SLXCHL001 October 9, 2015 Sunflowers, Vincent Van Gogh, 1888, The National Gallery 1

description

using vectors, MATLAB and latex to mathematically plot a sunflower head and to see how changing the golden angle changes the plot. How two equations plotted recursively creates a fractal and how a minimal change to the equations changes the entire plot. How the charge on a capacitor builds up over time with given base. All code given.

Transcript of Applied Mathematics Mam1044H sunflower and fractal project

Page 1: Applied Mathematics Mam1044H sunflower and fractal project

Applied Mathematics

MAM1044/MAM1043H

Chloe SoleSLXCHL001

October 9, 2015

Sunflowers, Vincent Van Gogh, 1888, The National Gallery

1

Page 2: Applied Mathematics Mam1044H sunflower and fractal project

Contents

1 Sunflower 61.1 Question: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.2 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.3 Code and Results . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2 Fractal 102.1 Question . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.2 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.3 Code and Results . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3 Charge on Capacitor 123.1 Question . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.2 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.3 Code and Results . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

2

Page 3: Applied Mathematics Mam1044H sunflower and fractal project

Abstract

Question 1:Sunflower Seeds

Sunflower seeds form in the Fibonacci sequence. To mathematically plotthe layout of a sunflower head we treat each seed as a position vector.Then one can plot them using their distance from the center and theta,the angle of incidence from a decided axis, where the length is defined as√n and theta πdn=180◦. n is the number of the seed which you are

defining and d is your angle of divergence between any two successiveseeds.

Figure 1: Sunflower seeds with an angle of divergence between any two successiveseeds being 137.51◦ and 137.61◦

As you can see from the above figure a small change in the angle ofdivergence results in a completely different plot pattern.

Question 2:Fractal

Fractals are beautiful structures, images or anything really that’sindividual parts are the same as the whole just on a smaller scale. Thisbeautiful recursive property of fractals make them much easier to model.Fractals occur in nature as you can see in Figure 2.

Figure 2: Ferns are an example of a visible reoccurring pattern in nature.

3

Page 4: Applied Mathematics Mam1044H sunflower and fractal project

A fractal can be plotted using a set of mathematical equations andwould become more detailed with and increased number of iterations.Given:

xk+1 = yk(1 + sin0.7xk)− 1.2absxk

yk+1 = 0.21− xkand

x0 = y0 = 0

If one plots the above equations for k being limited to a maximum valueof 100000 then we get the fractal seen in Figure 3 below.

4

Page 5: Applied Mathematics Mam1044H sunflower and fractal project

Question 3:Charge and Time

Figure 3: A circuit diagram of a resistor (R1), capacitor (C1) and battery (V)connected in series.

The capacitor in the above diagram begins to charge at time = 0. Thismeans that at time = 0 there is no accumulated charge on the capacitorsbut as time increases the one disk of the capacitor will accumulateelectrons and become inherently negative whereas the other disk willbecome increasingly positive.

The charge accumulated on the capacitors disks follows themathematical equation below:

Q(t) = CV (1− e−t/RC

Thus plotting time (x) versus charge (y) we get:

5

Page 6: Applied Mathematics Mam1044H sunflower and fractal project

Chapter 1

Sunflower

1.1 Question:

”The arrangement of seeds in a sunflower head follows a fixedmathematical pattern. The (nth) seed is at position r =

√n, with

angular co-ordinate πdn=180◦ radians, where d is the constant an-gle of divergence (in degrees) between any two successive seeds, i.e.between the nth and (n + 1)th seeds. A perfect sunflower head isgenerated by d = 137.51◦. Write a program to plot the seeds; usea circle for each seed. A remarkable feature of this model is thatthe angle d must be exact to get proper sunflowers. Experimentwith some different values, e.g. 137.45◦(spokes, from fairly far out),137.65◦ (spokes all the way), 137.92◦ (Catherine wheels) and plotyour results.”

1.2 Solution

Sunflower seeds form in the Fibonacci sequence. To mathematically plot thelayout of a sunflower head given that the (nth) seed is at position r =

√n with

angular co-ordinate πdn=180◦ radians, where n is the number of the seedwhich you are defining and d is your angle of divergence between any twosuccessive seeds, we can treat each seed as being a position vector written inpolar co-ordinates. Polar co-ordinates are a form of notation which allows aposition vector ~v = xex + yey to be written in terms of it’s

magnitude=√x2 + y2, which in this case is r, and the angle it makes with the

positive x axis. Setting the origin of our axes to the center of the sunflower ourfirst seed will be at position n=1, so r =

√1 = 1, and theta =

π(137.51◦)1=180◦ radians we plot the location of each seed in the head.

To solve this in terms of MATLAB there are three main algorithms that Iwould use. The first algorithm is the most time efficient one being that youcreate n being an element of 1 to 750 and then defining theta as beingπ(137.51◦)n=180. Doing this theta becomes an array of numbers as it has avalue for each value of n. Then we define r as being

√n. This also creates r

being an array of numbers one for each value of n.

The second algorithm is less time efficient but it does however result in theautomatic sequential coloring of the points in an ordered fashion allowing oneto see patterns within the sunflower head more easily. We start this algorithmby instantiating a variable n to 1. Then ensuring that MATLAB knows to notrefresh the graph for each individual point we define a while loop that will rununtil n is 1000. Then while in the loop we calculate the value of theta and raccording to that specific n value at that point, plot it and then increment nby one and begin the loop once more until n reaches 1000. When n reaches1000 the loops condition will no longer be true and therefore will not executethe enclosed code anymore.

The last algorithm I would use to solve this problem is similar to the secondone in terms of time efficiency and they both produce the same colorful plotdue to the use of ”figure; hold on;”. For this algorithm I used a for loop in theplace of the while loop so in basic structure it changed minorly.

6

Page 7: Applied Mathematics Mam1044H sunflower and fractal project

1.3 Code and Results

Version 1:

Figure 1.1: Sunflower head with the golden angle of divergence of 137.51◦

Figure 1.2: Sunflower heads with angles of 131.51◦ and 138.51◦ and 137.61◦

n=1:1:700;d=137.51;theta = pi*n*d/180;r = sqrt(n);polar(theta,r,'o')

7

Page 8: Applied Mathematics Mam1044H sunflower and fractal project

Version 2

Figure 1.3: Sunflower head with the golden angle of divergence of 137.51◦

Figure 1.4: Sunflower heads with angles of 90.45◦ and 10◦ and 190.45◦

figure; hold on;n=1;d=137.51;while n<1000,

theta = pi*n*d/180;r = sqrt(n);polar(theta,r,'o')n = n+1;

end

8

Page 9: Applied Mathematics Mam1044H sunflower and fractal project

Version 3

Figure 1.5: Sunflower head with the golden angle of divergence of 137.51◦

Figure 1.6: Sunflower heads with angles of 90.45◦ and 10◦ and 190.45◦

figure; hold on;d=137.51;for n=1:1000,

theta = pi*n*d/180;r = sqrt(n);polar(theta,r,'o')

end

9

Page 10: Applied Mathematics Mam1044H sunflower and fractal project

Chapter 2

Fractal

2.1 Question

”A rather beautiful fractal picture can be drawn by plotting thepoints (xk ; yk) generated by the following difference equations

xk+1 = yk(1 + sin0.7xk)− 1.2absxk

yk+1 = 0.21− xk

andx0 = y0 = 0

Write a program to draw the picture (plot individual points; do notjoin them).”

2.2 Solution

To solve this problem used a for loop to create an array of numbers forcoupled co-ordinates. and then plotted the entire array at the end to be mosttime efficient. Another algorithm could be used that would make use of awhile loop in place of the for loop.Potting the above equations in the question produces a fractal like plothowever if you plot these equations:

xk+1 = yk((1 + sin0.7xk)− 1.2absxk)

yk+1 = 0.21− xkand

x0 = y0 = 0

then you end up with a real fractal which always looks the same no matterhow far you zoom in.

2.3 Code and Results

Version 1:

10

Page 11: Applied Mathematics Mam1044H sunflower and fractal project

x = zeros(1, 100000);y = zeros(1, 100000);for k = 2:100000

x(k)= y(k-1)*(1+sin(0.7*x(k-1)))-1.2*abs(x(k-1));y(k)= 0.21-x(k-1);

endplot(x,y,'.')

Version 2:

x = zeros(1, 100000);y = zeros(1, 100000);for k = 2:100000

x(k)= y(k-1)*((1+sin(0.7*x(k-1)))-1.2*abs(x(k-1)));y(k)= 0.21-x(k-1);

endplot(x,y,'.')

11

Page 12: Applied Mathematics Mam1044H sunflower and fractal project

Chapter 3

Charge on Capacitor

3.1 Question

”When a resistor (R), capacitor (C) and battery (V ) are connectedin series, a charge Q builds up on the capacitor according to theformula Q(t) = CV (1−e−t/RC , if there is no charge on the capacitorat time t = 0. The problem is to monitor the charge on the capacitorevery 0:1 seconds in order to detect when it reaches a level of 8 unitsof charge, given that V = 9;R = 4 and C = 1. Write a program whichdisplays the time and charge every 0:1 seconds until the charge firstexceeds 8 units (i.e. the last charge displayed must exceed 8). Onceyou have done this, rewrite the program to display the charge onlywhile it is strictly less than 8 units.”

3.2 Solution

For the first part of the question I used a while loop to repeat code thatcalculates the value for q incrementing the value for time by 0.1 each loop. Atthe point at which q either becomes 8 or exceeds 8 the while loop will end. Wethen just insert a copy of the code that we are repeating so that it executes itonce more after the loop. Thus producing the results showing q until the firstvalue that exceeds 8.

The second part is exactly the same just without the copy of the repeatedcode outside of the while loop so it just eliminates the one q value that makesthe while loop invalid thus the results produced will be strictly less than 8.

3.3 Code and Results

First part of the question:

At time t=0 Q(t)=0At time t=1.000000e-01 Q(t)=2.222108e-01At time t=2.000000e-01 Q(t)=4.389352e-01

12

Page 13: Applied Mathematics Mam1044H sunflower and fractal project

At time t=3.000000e-01 Q(t)=6.503086e-01At time t=4.000000e-01 Q(t)=8.564632e-01At time t=5.000000e-01 Q(t)=1.057528e+00At time t=6.000000e-01 Q(t)=1.253628e+00At time t=7.000000e-01 Q(t)=1.444887e+00At time t=8.000000e-01 Q(t)=1.631423e+00At time t=9.000000e-01 Q(t)=1.813354e+00At time t=1.000000e+00 Q(t)=1.990793e+00At time t=1.100000e+00 Q(t)=2.163851e+00At time t=1.200000e+00 Q(t)=2.332636e+00At time t=1.300000e+00 Q(t)=2.497254e+00At time t=1.400000e+00 Q(t)=2.657807e+00At time t=1.500000e+00 Q(t)=2.814396e+00At time t=1.600000e+00 Q(t)=2.967120e+00At time t=1.700000e+00 Q(t)=3.116072e+00At time t=1.800000e+00 Q(t)=3.261347e+00At time t=1.900000e+00 Q(t)=3.403034e+00At time t=2.000000e+00 Q(t)=3.541224e+00At time t=2.100000e+00 Q(t)=3.676002e+00At time t=2.200000e+00 Q(t)=3.807452e+00At time t=2.300000e+00 Q(t)=3.935656e+00At time t=2.400000e+00 Q(t)=4.060695e+00At time t=2.500000e+00 Q(t)=4.182647e+00At time t=2.600000e+00 Q(t)=4.301588e+00At time t=2.700000e+00 Q(t)=4.417592e+00At time t=2.800000e+00 Q(t)=4.530732e+00At time t=2.900000e+00 Q(t)=4.641079e+00At time t=3.000000e+00 Q(t)=4.748701e+00At time t=3.100000e+00 Q(t)=4.853666e+00At time t=3.200000e+00 Q(t)=4.956039e+00At time t=3.300000e+00 Q(t)=5.055885e+00At time t=3.400000e+00 Q(t)=5.153266e+00At time t=3.500000e+00 Q(t)=5.248242e+00At time t=3.600000e+00 Q(t)=5.340873e+00At time t=3.700000e+00 Q(t)=5.431217e+00At time t=3.800000e+00 Q(t)=5.519331e+00At time t=3.900000e+00 Q(t)=5.605269e+00At time t=4.000000e+00 Q(t)=5.689085e+00At time t=4.100000e+00 Q(t)=5.770832e+00At time t=4.200000e+00 Q(t)=5.850560e+00At time t=4.300000e+00 Q(t)=5.928320e+00At time t=4.400000e+00 Q(t)=6.004160e+00At time t=4.500000e+00 Q(t)=6.078128e+00At time t=4.600000e+00 Q(t)=6.150269e+00At time t=4.700000e+00 Q(t)=6.220629e+00At time t=4.800000e+00 Q(t)=6.289252e+00At time t=4.900000e+00 Q(t)=6.356181e+00At time t=5.000000e+00 Q(t)=6.421457e+00At time t=5.100000e+00 Q(t)=6.485121e+00At time t=5.200000e+00 Q(t)=6.547214e+00At time t=5.300000e+00 Q(t)=6.607773e+00At time t=5.400000e+00 Q(t)=6.666838e+00At time t=5.500000e+00 Q(t)=6.724444e+00At time t=5.600000e+00 Q(t)=6.780627e+00At time t=5.700000e+00 Q(t)=6.835424e+00At time t=5.800000e+00 Q(t)=6.888867e+00At time t=5.900000e+00 Q(t)=6.940991e+00At time t=6.000000e+00 Q(t)=6.991829e+00At time t=6.100000e+00 Q(t)=7.041410e+00At time t=6.200000e+00 Q(t)=7.089768e+00At time t=6.300000e+00 Q(t)=7.136932e+00At time t=6.400000e+00 Q(t)=7.182931e+00At time t=6.500000e+00 Q(t)=7.227795e+00At time t=6.600000e+00 Q(t)=7.271551e+00At time t=6.700000e+00 Q(t)=7.314226e+00At time t=6.800000e+00 Q(t)=7.355848e+00At time t=6.900000e+00 Q(t)=7.396443e+00At time t=7.000000e+00 Q(t)=7.436035e+00At time t=7.100000e+00 Q(t)=7.474649e+00

13

Page 14: Applied Mathematics Mam1044H sunflower and fractal project

At time t=7.200000e+00 Q(t)=7.512310e+00At time t=7.300000e+00 Q(t)=7.549041e+00At time t=7.400000e+00 Q(t)=7.584866e+00At time t=7.500000e+00 Q(t)=7.619805e+00At time t=7.600000e+00 Q(t)=7.653882e+00At time t=7.700000e+00 Q(t)=7.687118e+00At time t=7.800000e+00 Q(t)=7.719533e+00At time t=7.900000e+00 Q(t)=7.751148e+00At time t=8.000000e+00 Q(t)=7.781982e+00At time t=8.100000e+00 Q(t)=7.812055e+00At time t=8.200000e+00 Q(t)=7.841386e+00At time t=8.300000e+00 Q(t)=7.869992e+00At time t=8.400000e+00 Q(t)=7.897892e+00At time t=8.500000e+00 Q(t)=7.925103e+00At time t=8.600000e+00 Q(t)=7.951643e+00At time t=8.700000e+00 Q(t)=7.977527e+00At time t=8.800000e+00 Q(t)=8.002772e+00

v = 9;t = 0;

c = 1;r = 4;

figure; hold on;q =c*v*(1-exp(-t/r*c));title('Graph showing the change in Charge (C) over Time (sec):');xlabel('Time (sec)');ylabel('Charge (C)');while q<8,

plot(t,q,'.');fprintf('At time t=%d Q(t)=%d \n',t,q);

t=t+0.1;q =c*v*(1-exp(-t/r*c));

endfprintf('At time t=%d Q(t)=%d \n',t,q);plot(t,q,'.');

Second part of the Question

14

Page 15: Applied Mathematics Mam1044H sunflower and fractal project

At time t=0 Q(t)=0At time t=1.000000e-01 Q(t)=2.222108e-01At time t=2.000000e-01 Q(t)=4.389352e-01At time t=3.000000e-01 Q(t)=6.503086e-01At time t=4.000000e-01 Q(t)=8.564632e-01At time t=5.000000e-01 Q(t)=1.057528e+00At time t=6.000000e-01 Q(t)=1.253628e+00At time t=7.000000e-01 Q(t)=1.444887e+00At time t=8.000000e-01 Q(t)=1.631423e+00At time t=9.000000e-01 Q(t)=1.813354e+00At time t=1.000000e+00 Q(t)=1.990793e+00At time t=1.100000e+00 Q(t)=2.163851e+00At time t=1.200000e+00 Q(t)=2.332636e+00At time t=1.300000e+00 Q(t)=2.497254e+00At time t=1.400000e+00 Q(t)=2.657807e+00At time t=1.500000e+00 Q(t)=2.814396e+00At time t=1.600000e+00 Q(t)=2.967120e+00At time t=1.700000e+00 Q(t)=3.116072e+00At time t=1.800000e+00 Q(t)=3.261347e+00At time t=1.900000e+00 Q(t)=3.403034e+00At time t=2.000000e+00 Q(t)=3.541224e+00At time t=2.100000e+00 Q(t)=3.676002e+00At time t=2.200000e+00 Q(t)=3.807452e+00At time t=2.300000e+00 Q(t)=3.935656e+00At time t=2.400000e+00 Q(t)=4.060695e+00At time t=2.500000e+00 Q(t)=4.182647e+00At time t=2.600000e+00 Q(t)=4.301588e+00At time t=2.700000e+00 Q(t)=4.417592e+00At time t=2.800000e+00 Q(t)=4.530732e+00At time t=2.900000e+00 Q(t)=4.641079e+00At time t=3.000000e+00 Q(t)=4.748701e+00At time t=3.100000e+00 Q(t)=4.853666e+00At time t=3.200000e+00 Q(t)=4.956039e+00At time t=3.300000e+00 Q(t)=5.055885e+00At time t=3.400000e+00 Q(t)=5.153266e+00At time t=3.500000e+00 Q(t)=5.248242e+00At time t=3.600000e+00 Q(t)=5.340873e+00At time t=3.700000e+00 Q(t)=5.431217e+00At time t=3.800000e+00 Q(t)=5.519331e+00At time t=3.900000e+00 Q(t)=5.605269e+00At time t=4.000000e+00 Q(t)=5.689085e+00At time t=4.100000e+00 Q(t)=5.770832e+00At time t=4.200000e+00 Q(t)=5.850560e+00At time t=4.300000e+00 Q(t)=5.928320e+00At time t=4.400000e+00 Q(t)=6.004160e+00At time t=4.500000e+00 Q(t)=6.078128e+00At time t=4.600000e+00 Q(t)=6.150269e+00At time t=4.700000e+00 Q(t)=6.220629e+00At time t=4.800000e+00 Q(t)=6.289252e+00At time t=4.900000e+00 Q(t)=6.356181e+00At time t=5.000000e+00 Q(t)=6.421457e+00At time t=5.100000e+00 Q(t)=6.485121e+00At time t=5.200000e+00 Q(t)=6.547214e+00At time t=5.300000e+00 Q(t)=6.607773e+00At time t=5.400000e+00 Q(t)=6.666838e+00At time t=5.500000e+00 Q(t)=6.724444e+00At time t=5.600000e+00 Q(t)=6.780627e+00At time t=5.700000e+00 Q(t)=6.835424e+00At time t=5.800000e+00 Q(t)=6.888867e+00At time t=5.900000e+00 Q(t)=6.940991e+00At time t=6.000000e+00 Q(t)=6.991829e+00At time t=6.100000e+00 Q(t)=7.041410e+00At time t=6.200000e+00 Q(t)=7.089768e+00At time t=6.300000e+00 Q(t)=7.136932e+00At time t=6.400000e+00 Q(t)=7.182931e+00At time t=6.500000e+00 Q(t)=7.227795e+00At time t=6.600000e+00 Q(t)=7.271551e+00At time t=6.700000e+00 Q(t)=7.314226e+00At time t=6.800000e+00 Q(t)=7.355848e+00

15

Page 16: Applied Mathematics Mam1044H sunflower and fractal project

At time t=6.900000e+00 Q(t)=7.396443e+00At time t=7.000000e+00 Q(t)=7.436035e+00At time t=7.100000e+00 Q(t)=7.474649e+00At time t=7.200000e+00 Q(t)=7.512310e+00At time t=7.300000e+00 Q(t)=7.549041e+00At time t=7.400000e+00 Q(t)=7.584866e+00At time t=7.500000e+00 Q(t)=7.619805e+00At time t=7.600000e+00 Q(t)=7.653882e+00At time t=7.700000e+00 Q(t)=7.687118e+00At time t=7.800000e+00 Q(t)=7.719533e+00At time t=7.900000e+00 Q(t)=7.751148e+00At time t=8.000000e+00 Q(t)=7.781982e+00At time t=8.100000e+00 Q(t)=7.812055e+00At time t=8.200000e+00 Q(t)=7.841386e+00At time t=8.300000e+00 Q(t)=7.869992e+00At time t=8.400000e+00 Q(t)=7.897892e+00At time t=8.500000e+00 Q(t)=7.925103e+00At time t=8.600000e+00 Q(t)=7.951643e+00At time t=8.700000e+00 Q(t)=7.977527e+00

v = 9;t = 0;

c = 1;r = 4;

figure; hold on;q =c*v*(1-exp(-t/r*c));title('Graph showing the change in Charge (C) over Time (sec):');xlabel('Time (sec)');ylabel('Charge (C)');while q<8,

plot(t,q,'.');fprintf('At time t=%d Q(t)=%d \n',t,q);

t=t+0.1;q =c*v*(1-exp(-t/r*c));

end

16