Directions: In this assignment you will write two Python scripts to generate a Fractal for the Julia set of a (complex-valued) transformation related to Newton’s root finding method.

© All Rights Reserved

494 views

Directions: In this assignment you will write two Python scripts to generate a Fractal for the Julia set of a (complex-valued) transformation related to Newton’s root finding method.

© All Rights Reserved

- Compute's Guide to Adventure Games
- Communicating Science: Giving Talks (Second Edition)
- Merkle Hellman Knapsack
- Minsky, Marvin, 'the Society of Mind'
- Runge Kutta Lab with Pendulum Problem
- Getting Your Way Every Day Mastering the Lost Art of Pure Persuasion
- Moving On: Managing Career Transitions
- Commodore 64 Adventures
- turing machine
- Notes on Graph Theory
- Python Scientific Simple
- Game Theory and Humanities
- Vector Calculus Review
- 2004 - How to Persuade People Who Don't Want to Be Persuaded Get What You Want Every Time ---- Joel Bauer
- Rational and Cumulative Review
- Sa Orasan Ni Ginoong Abad Ay 5
- SUMSEM1-2018-19 ECE2010 ETH VL2018198000764 Reference Material I 03-May-2019 Module-4 Part-I - Copy
- CSBD.pdf
- numerical analysis
- Numerical Analysis

You are on page 1of 19

Lab 3

Joshua Cook

October 28, 2014

Preliminaries

0.1

zn+1 = zn a

p(zn )

p0 (zn )

where a is any complex number. The special choice a = 1 corresponds to the Newton fractal.

The fixed points of this map are stable when a lies inside the disk of radius 1 centered at 1. When a is outside

this disk, the fixed points are locally unstable, however the map still exhibits a fractal structure in the sense

of the Julia set. If p is a polynomial of degree n, then the sequence zn is bounded provided that a is inside a

disk of radius n centered at n.

More generally, Newtons fractal is a special case of a Julia set.

0.2

Import Statement

import math

import numpy as np

from scipy.misc import derivative

import matplotlib

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

from matplotlib import cm

%matplotlib inline

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

1

Write a Python function that takes as input the integer n and returns a 1d numpy array of length n holding

the n roots of unity; that is, the n roots of the polynomial

zn 1 = 0

def unity_roots(n):

roots = np.zeros((n,1), dtype=complex)

for i in range(n):

theta = 2*i*math.pi/n

re = math.cos(theta)

im = math.sin(theta)

roots[i] = re + im*1j

return roots

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

2

Write a Python function named nfractal that takes as input four arguments: K, pixel, tol, and n, and

1. generates a mesh of the complex plane consisting of pixel points along the x-axis and 0.75*pixel

points along the x-axis, with x, y [1.5, 1.5].

k)

2. applies the iteration zk+1 = zk a pp(z

0 (z ) to each z = x + iy on the mesh K times and records the number

k

of times that the iterated value is within tol distance to one of the roots of the polynomial p(z).

3. colors each point in the mesh grid according to the number of times it is within a distance tol of one

of the roots of the polynomial p(z).

2.1

Define Function

# generate mesh

x = np.linspace(-1.5,1.5,pixel)

y = np.linspace(-1.5,1.5,0.75*pixel)

[Re,Im] = np.meshgrid(x,y)

# onesmatrix is a math construct for use in algorithm

onesmatrix = np.ones((0.75*pixel,pixel),float)

# B stores convergence/divergence values

B = np.zeros((0.75*pixel,pixel),float)

# C stores our iterated values i.e. our z_n+1 for each location on the complex plane

C = np.zeros((0.75*pixel,pixel),complex)

C = Re + Im*1j

Cn = C

def p(x): return (x**n) - 1

def pp(x): return n*x**(n-1)

roots = unity_roots(n)

for i in range(K):

Cn = Cn - a*p(Cn)/pp(Cn)

for j in range(n):

B = B + (np.abs(Cn-onesmatrix*roots[j])< tol)

plt.pcolormesh(x,y,B,cmap='spring')

return Re, Im, B

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

# generate mesh

x = np.linspace(-1.5,1.5,pixel)

y = np.linspace(-1.5,1.5,0.75*pixel)

[Re,Im] = np.meshgrid(x,y)

# onesmatrix is a math construct for use in algorithm

onesmatrix = np.ones((0.75*pixel,pixel),float)

# B stores convergence/divergence values

R = np.zeros((0.75*pixel,pixel),float)

G = np.zeros((0.75*pixel,pixel),float)

B = np.zeros((0.75*pixel,pixel),float)

im = np.zeros((0.75*pixel,pixel,3),float)

# C stores our iterated values i.e. our z_n+1 for each location on the complex plane

C = np.zeros((0.75*pixel,pixel),complex)

C = Re + Im*1j

Cn = C

def p(x): return (x**n) - 1

def pp(x): return n*x**(n-1)

roots = unity_roots(n)

for i in range(K):

Cn = Cn - a*p(Cn)/pp(Cn)

if (invert == 1):

for j in range(n):

if (j%3 == 0):

R = R + (np.abs(Cn-onesmatrix*roots[j])>tol)

if (j%3 == 1):

G = G + (np.abs(Cn-onesmatrix*roots[j])>tol)

if (j%3 == 2):

B = B + (np.abs(Cn-onesmatrix*roots[j])>tol)

if (invert == 0):

for j in range(n):

if (j%3 == 0):

R = R + (np.abs(Cn-onesmatrix*roots[j])<tol)

if (j%3 == 1):

G = G + (np.abs(Cn-onesmatrix*roots[j])<tol)

if (j%3 == 2):

B = B + (np.abs(Cn-onesmatrix*roots[j])<tol)

R = R *(510/K)

Numerical Analysis

Lab 3

G = G *(510/K)

B = B *(510/K)

im[:,:,0] = R

im[:,:,1] = G

im[:,:,2] = B

plt.imshow(im)

return Re, Im, B

frac = nfractal(60,1000,10E-6,2)

Joshua Cook

October 28, 2014

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

Numerical Analysis

Lab 3

Joshua Cook

October 28, 2014

- Compute's Guide to Adventure GamesUploaded byCubemanPDX
- Communicating Science: Giving Talks (Second Edition)Uploaded byRuss Campbell
- Merkle Hellman KnapsackUploaded bychitrg
- Minsky, Marvin, 'the Society of Mind'Uploaded byapi-3834106
- Getting Your Way Every Day Mastering the Lost Art of Pure PersuasionUploaded byspamme1
- Moving On: Managing Career TransitionsUploaded byRuss Campbell
- Commodore 64 AdventuresUploaded byCubemanPDX
- Python Scientific SimpleUploaded byMusyarofah Hanafi
- turing machineUploaded bysheetal taneja
- Game Theory and HumanitiesUploaded byjolreal
- 2004 - How to Persuade People Who Don't Want to Be Persuaded Get What You Want Every Time ---- Joel BauerUploaded byKen Sai Pang
- Rational and Cumulative ReviewUploaded byKenzie Pattison
- Sa Orasan Ni Ginoong Abad Ay 5Uploaded bymaloy
- SUMSEM1-2018-19 ECE2010 ETH VL2018198000764 Reference Material I 03-May-2019 Module-4 Part-I - CopyUploaded bySatyam kumar Jha

- Runge Kutta Lab with Pendulum ProblemUploaded byJoshua Cook
- CSBD.pdfUploaded byJoshua Cook
- numerical analysisUploaded byJoshua Cook
- Numerical AnalysisUploaded byJoshua Cook
- Notes on Graph TheoryUploaded byJoshua Cook
- Vector Calculus ReviewUploaded byJoshua Cook
- Numerical AnalysisUploaded byJoshua Cook
- Zernike PolynomialsUploaded byJoshua Cook
- linear algebra and combinatoricsUploaded byJoshua Cook
- RelationsUploaded byJoshua Cook
- linear regression in pythonUploaded byJoshua Cook

- A Method to Optimise Train Energy Consumption Combining Manual Energy EE and ShedulingUploaded byXú Vivian Parreira
- Lecture 33Uploaded byEd Z
- High Performance Abaqus Simulation in Soil Mechanics-huegel_henke_kinzlerUploaded byAnonymous FOt6t3N
- Mysql Help 123Uploaded byJohn Smith
- Lean-7waste,takt time,crew sizeUploaded byapi-3770121
- Creativity TechniquesUploaded byjcabbud
- Discover ManualDrillHolesUploaded byLuis Munoz
- Graphics and GUI theory Using MatlabUploaded bySaloni Agarwal
- 4 6filter BanksUploaded byAejaz Aamer
- 13 15.Electrical EngineeringUploaded byRahul Shah
- Fluid Mechanics Mory 2Uploaded byazamat
- The AeM December 2016Uploaded byAjayGupta
- Angle Beam Trig Calculations - Ultrasonic TestingUploaded byArjun Rawat
- IXL Math and English _ Online Math and Language Arts PracticeUploaded byjasan3000
- Analysis of Latent Heat Storage Devices With FinsUploaded byhello_ashish22
- X Ray DiffractionUploaded byS.m. Chandrashekar
- Lect2UP350_(100328)Uploaded byrkatreep
- Toluene KineticsUploaded byDavid Paex
- 01 Integration by Parts - HandoutUploaded by011100111
- Thermodynamics Lecture 6 (2)Uploaded byMariah Nicol
- Entrada Bueno NQ32326Uploaded bygarridolopez
- GBq ChartUploaded byphillipskincaid
- Fm f SamplesUploaded byPiyush Sakrikar
- Flnn Question BankUploaded byDevLaxman
- Homework2 - Denis DantasUploaded byDenis Dantas
- Buss MannUploaded bycocacolapepsi
- Bunte_KliewerUploaded byBenjamin Naula
- Jacobi Stability of Different Competition Models K. MishraUploaded byInternational Journal of Creative Mathematical Sciences and Technology
- HandoutUploaded bysindu_lawrence
- GPS tracker Communication__ Protocol V1.51.pdfUploaded bySamit Jain

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.