SlideShare a Scribd company logo
1 of 2
2) A fractal is a curve or geometric figure comprised of a pattern that repeats at every scale. One
approach to generating a fractal is called a chaos game. A chaos game is an algorithm in which
points are plotted iteratively according to small set of rules. After a sufficient number of points
are plotted, a pattern emerges. A section of the boundary of the Dragon Curve fractal can be
plotted in MATLAB using the chaos game approach by plotting points iteratively according to
one of the following three rules that are selected randomly with equal probability. (You will need
to look up the randi function.) Write a MATLAB script that calculates the x and y vectors, then
plots x vs y using plot(x,y,'.r'). Start with x1 = 0 and y1 = 1. Perform 50000 iterations. Hint 1:
At each iteration you'll calculate a new x and y from the old x and y. Which rule you use to
calculate the new x and y is determined by ''flipping a coin'' (randi). This coin flip happens
every iteration.
Solution
Matlab Code:
x(1)=0;
y(1)=1; % Initially setting x=0;y=1
for i=1:50000 % looping from 1 to 50000
p=randi(3); % Generating a random number 1,2 or 3 will be generated
if p==1 % Initially i=1 will be selected and it will check whether randi() generated 1,2 or 3.
x(i+1)=((x(i)-y(i))/4)-(1/2); % if randi(3) generated 1 it will come to this line
y(i+1)=((x(i)+y(i))/4)+1;
else if p==2 % if randi(3) generated 2 it will execute this loop
x(i+1)=((y(i)-x(i))/4)+(1/2);
y(i+1)=-((x(i)+y(i))/4)+1;
else if p==3 % if randi(3) generated 3 it will execute this loop and will generate x,y from
previous values
x(i+1)=((x(i)+y(i))/2)+1;
y(i+1)=((y(i)-x(i))/2);
end
end
end
end % In this way we get a vector of x,y values and now we plot them
plot(x,y,'.r')
2) A fractal is a curve or geometric figure comprised of a pattern tha.docx

More Related Content

Similar to 2) A fractal is a curve or geometric figure comprised of a pattern tha.docx

Research Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and ScienceResearch Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and Scienceresearchinventy
 
Chi-squared Goodness of Fit Test Project Overview and.docx
Chi-squared Goodness of Fit Test Project  Overview and.docxChi-squared Goodness of Fit Test Project  Overview and.docx
Chi-squared Goodness of Fit Test Project Overview and.docxmccormicknadine86
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxDevaraj Chilakala
 
A25-7 Quadratic Inequalities
A25-7 Quadratic InequalitiesA25-7 Quadratic Inequalities
A25-7 Quadratic Inequalitiesvhiggins1
 
Rasterization.pptx
Rasterization.pptxRasterization.pptx
Rasterization.pptxAhmadAbba6
 
Numerical Methods and Applied Statistics Paper (RTU VI Semester)
Numerical Methods and Applied Statistics Paper (RTU VI Semester)Numerical Methods and Applied Statistics Paper (RTU VI Semester)
Numerical Methods and Applied Statistics Paper (RTU VI Semester)FellowBuddy.com
 
The world of loss function
The world of loss functionThe world of loss function
The world of loss function홍배 김
 
Matlab cheatsheet
Matlab cheatsheetMatlab cheatsheet
Matlab cheatsheetlokeshkumer
 
5.2 using intercepts
5.2 using intercepts5.2 using intercepts
5.2 using interceptscoolhanddav
 
5.2 using intercepts
5.2 using intercepts5.2 using intercepts
5.2 using interceptscoolhanddav
 
Vertical asymptotes to rational functions
Vertical asymptotes to rational functionsVertical asymptotes to rational functions
Vertical asymptotes to rational functionsTarun Gehlot
 
Rational Functions
Rational FunctionsRational Functions
Rational FunctionsJazz0614
 
COMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptxCOMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptximman gwu
 

Similar to 2) A fractal is a curve or geometric figure comprised of a pattern tha.docx (20)

Research Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and ScienceResearch Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and Science
 
Chi-squared Goodness of Fit Test Project Overview and.docx
Chi-squared Goodness of Fit Test Project  Overview and.docxChi-squared Goodness of Fit Test Project  Overview and.docx
Chi-squared Goodness of Fit Test Project Overview and.docx
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptx
 
A25-7 Quadratic Inequalities
A25-7 Quadratic InequalitiesA25-7 Quadratic Inequalities
A25-7 Quadratic Inequalities
 
Rasterization.pptx
Rasterization.pptxRasterization.pptx
Rasterization.pptx
 
Numerical Methods and Applied Statistics Paper (RTU VI Semester)
Numerical Methods and Applied Statistics Paper (RTU VI Semester)Numerical Methods and Applied Statistics Paper (RTU VI Semester)
Numerical Methods and Applied Statistics Paper (RTU VI Semester)
 
Lec3
Lec3Lec3
Lec3
 
The world of loss function
The world of loss functionThe world of loss function
The world of loss function
 
Matlab cheatsheet
Matlab cheatsheetMatlab cheatsheet
Matlab cheatsheet
 
Final exam mariluz 1
Final exam mariluz 1Final exam mariluz 1
Final exam mariluz 1
 
5.2 using intercepts
5.2 using intercepts5.2 using intercepts
5.2 using intercepts
 
5.2 using intercepts
5.2 using intercepts5.2 using intercepts
5.2 using intercepts
 
Commands list
Commands listCommands list
Commands list
 
Matlab tutorial 2
Matlab tutorial 2Matlab tutorial 2
Matlab tutorial 2
 
Vertical asymptotes to rational functions
Vertical asymptotes to rational functionsVertical asymptotes to rational functions
Vertical asymptotes to rational functions
 
Rational Functions
Rational FunctionsRational Functions
Rational Functions
 
Ses 3 quadratic equations
Ses 3 quadratic equationsSes 3 quadratic equations
Ses 3 quadratic equations
 
Lesson 8
Lesson 8Lesson 8
Lesson 8
 
COMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptxCOMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptx
 
Regression
RegressionRegression
Regression
 

More from lcarolyn

1Experimental Chemistry Data Analysis 1- How do you know when to name.docx
1Experimental Chemistry Data Analysis 1- How do you know when to name.docx1Experimental Chemistry Data Analysis 1- How do you know when to name.docx
1Experimental Chemistry Data Analysis 1- How do you know when to name.docxlcarolyn
 
18) Explain why oil and water do not mix- A) Water is not able to ioni.docx
18) Explain why oil and water do not mix- A) Water is not able to ioni.docx18) Explain why oil and water do not mix- A) Water is not able to ioni.docx
18) Explain why oil and water do not mix- A) Water is not able to ioni.docxlcarolyn
 
17-Calcium sulfate has a soluble form in water- formed according to-.docx
17-Calcium sulfate has a soluble form in water- formed according to-.docx17-Calcium sulfate has a soluble form in water- formed according to-.docx
17-Calcium sulfate has a soluble form in water- formed according to-.docxlcarolyn
 
2- Does evolution violate the second law of thermodynamics- Why or why.docx
2- Does evolution violate the second law of thermodynamics- Why or why.docx2- Does evolution violate the second law of thermodynamics- Why or why.docx
2- Does evolution violate the second law of thermodynamics- Why or why.docxlcarolyn
 
2- Discuss the advantages and disadvantages of using the following com.docx
2- Discuss the advantages and disadvantages of using the following com.docx2- Discuss the advantages and disadvantages of using the following com.docx
2- Discuss the advantages and disadvantages of using the following com.docxlcarolyn
 
2- Create a multi - step Income Statement- Statement of Retained Earni.docx
2- Create a multi - step Income Statement- Statement of Retained Earni.docx2- Create a multi - step Income Statement- Statement of Retained Earni.docx
2- Create a multi - step Income Statement- Statement of Retained Earni.docxlcarolyn
 
2- Compare teh payment of cash divididends- stock dividends and purcha.docx
2- Compare teh payment of cash divididends- stock dividends and purcha.docx2- Compare teh payment of cash divididends- stock dividends and purcha.docx
2- Compare teh payment of cash divididends- stock dividends and purcha.docxlcarolyn
 

More from lcarolyn (7)

1Experimental Chemistry Data Analysis 1- How do you know when to name.docx
1Experimental Chemistry Data Analysis 1- How do you know when to name.docx1Experimental Chemistry Data Analysis 1- How do you know when to name.docx
1Experimental Chemistry Data Analysis 1- How do you know when to name.docx
 
18) Explain why oil and water do not mix- A) Water is not able to ioni.docx
18) Explain why oil and water do not mix- A) Water is not able to ioni.docx18) Explain why oil and water do not mix- A) Water is not able to ioni.docx
18) Explain why oil and water do not mix- A) Water is not able to ioni.docx
 
17-Calcium sulfate has a soluble form in water- formed according to-.docx
17-Calcium sulfate has a soluble form in water- formed according to-.docx17-Calcium sulfate has a soluble form in water- formed according to-.docx
17-Calcium sulfate has a soluble form in water- formed according to-.docx
 
2- Does evolution violate the second law of thermodynamics- Why or why.docx
2- Does evolution violate the second law of thermodynamics- Why or why.docx2- Does evolution violate the second law of thermodynamics- Why or why.docx
2- Does evolution violate the second law of thermodynamics- Why or why.docx
 
2- Discuss the advantages and disadvantages of using the following com.docx
2- Discuss the advantages and disadvantages of using the following com.docx2- Discuss the advantages and disadvantages of using the following com.docx
2- Discuss the advantages and disadvantages of using the following com.docx
 
2- Create a multi - step Income Statement- Statement of Retained Earni.docx
2- Create a multi - step Income Statement- Statement of Retained Earni.docx2- Create a multi - step Income Statement- Statement of Retained Earni.docx
2- Create a multi - step Income Statement- Statement of Retained Earni.docx
 
2- Compare teh payment of cash divididends- stock dividends and purcha.docx
2- Compare teh payment of cash divididends- stock dividends and purcha.docx2- Compare teh payment of cash divididends- stock dividends and purcha.docx
2- Compare teh payment of cash divididends- stock dividends and purcha.docx
 

Recently uploaded

Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleCeline George
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 

Recently uploaded (20)

Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP Module
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 

2) A fractal is a curve or geometric figure comprised of a pattern tha.docx

  • 1. 2) A fractal is a curve or geometric figure comprised of a pattern that repeats at every scale. One approach to generating a fractal is called a chaos game. A chaos game is an algorithm in which points are plotted iteratively according to small set of rules. After a sufficient number of points are plotted, a pattern emerges. A section of the boundary of the Dragon Curve fractal can be plotted in MATLAB using the chaos game approach by plotting points iteratively according to one of the following three rules that are selected randomly with equal probability. (You will need to look up the randi function.) Write a MATLAB script that calculates the x and y vectors, then plots x vs y using plot(x,y,'.r'). Start with x1 = 0 and y1 = 1. Perform 50000 iterations. Hint 1: At each iteration you'll calculate a new x and y from the old x and y. Which rule you use to calculate the new x and y is determined by ''flipping a coin'' (randi). This coin flip happens every iteration. Solution Matlab Code: x(1)=0; y(1)=1; % Initially setting x=0;y=1 for i=1:50000 % looping from 1 to 50000 p=randi(3); % Generating a random number 1,2 or 3 will be generated if p==1 % Initially i=1 will be selected and it will check whether randi() generated 1,2 or 3. x(i+1)=((x(i)-y(i))/4)-(1/2); % if randi(3) generated 1 it will come to this line y(i+1)=((x(i)+y(i))/4)+1; else if p==2 % if randi(3) generated 2 it will execute this loop x(i+1)=((y(i)-x(i))/4)+(1/2); y(i+1)=-((x(i)+y(i))/4)+1; else if p==3 % if randi(3) generated 3 it will execute this loop and will generate x,y from previous values x(i+1)=((x(i)+y(i))/2)+1; y(i+1)=((y(i)-x(i))/2); end end end end % In this way we get a vector of x,y values and now we plot them plot(x,y,'.r')