Iteration is the repetition of the same process over and over again. It is a crucial...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Iteration is the repetition of the same process over and over again. It is a crucial programming tool that we will get some practice using this week. To get started, lets recall matrix-vector multiplication. In two dimensions, matrix-vector multiplication is computed according to the following process: which can be written simply as: where x and y are 2-by-1 vectors: and A is a 2-by-2 matrix: y(1) = A(1,1) x(1) + A(1,2) = x(2) y(2) = A(2,2) x(2) + A(2,2)=x(2) A [0 1; -1 0]; x = [1; 1]; y = A *x x=[x2], x=[2] X= y [A(1,1) A(1,2)] A(2,1) A(2,2) Let's examine the effect of iterating matrix-vector multiplication with A=1₁3 • Create a Matlab script entitled 'matVecPlot.m' to run the following code: y = A*x; plot ( [0 x(1)],[0 x(2)]); hold on plot([0 y(1)],[0 y(2)], 'r'); y = A*y; plot ( [0 y(1)], [0 (2)],"g-'); y = A*y; plot ( [@ y(1)], 10 y(2)], 'y-.'); axis equal Once you get it working, examine what the code is doing. Practice thoroughly commenting your script to describe what it does (in the header) and what each line of code is doing. Check out coinFlipping.m to see an example. Problem 1: A rotation matrix has the general form: [cos (0) (sin(0) A -sin (0)] si cos(0) where defines the angle of rotation. For example, setting = yields the matrix we employed in matVecPlot.m (try it, just to be sure). We will now use a rotation matrix to visualize the unit circle. Let's start by altering our existing script: Make sure there are no other figures open close all; % Delete all variables in the workspace clear & Value of theta that will get you around the circle in 4 iterations theta = (2*pi)/4; & Construct the rotation matrix for theta A = [cos (theta) -sin(theta); sin (theta) cos (theta)]; & Plot the initial point (iteration 1) x = [1; 1]; plot (x (1),x(2), 'b*'); hold on * Iteration 2 x = A*x; plot(x(1),x(2), 'b*') % Iteration 3 x = A*x; plot (x (1), x(2), 'b*') % Iteration 4 plot(x(1),x(2), 'b*') title('n = 4'); hold off; axis equal The above code uses only four points to visualize the unit circle. Ask yourself, how is this code different from 'matVecPlot.m'? How would one go about adjusting this code to plot 125 points on the unit circle? Generalize the above code to create a function unitCircle.m that plots n points on the unit circle (use a for-loop). Be sure to include a header, thorough comments, proper code indentation, and incorporate an informative title to your plot that includes your name. Tum in a a plot for n = 125. Problem 2: Grow a Fern In Problem 1, we used a rotation matrix to visualize the unit circle. In this problem, we will grow a fern using more general affine transformations: y = A *x + b where b is a 2-by-1 vector that "shifts" the positions of A*x. Affine transformations can encode rotation, stretching, and shifting (assuming A is invertible, but don't worry about that now), and despite their simplicity, are used in many important applications. Here's a very well-known and interesting example from brain image analysis: https://www.sciencedirect.com/science/article/pii/S1361841501000366?via%3Dihub We are going to mathematically model our fern with a fractal and use a simple Iterated Function System: https://en.wikipedia.org/wiki/lterated function system. Though I'm sure we would all greatly enjoy delving into the mathematics behind fractals, for this exercise, we only need to write a code that iteratively grows the fern. Specifically, for each iteration, your code fern.m should generate a random number and Apply x = [0 0;0 0.16]** Apply x = [0.85 0.04; -0.04 0.85]*x + [0; 1.6] Apply x = [0.2 -0.26; 0.23 0.22] *x + [0; 1.61; Apply x = [-0.15 0.28; 0.26 0.24] *x + [0; 0.44]; with probability p = 0.07 with probability p = 0.01 with probability p = 0.85 with probability p = 0.07 Initialize your iteration with x = [0; 0)] and run the iteration for n = 2750 times. Be sure to include a header, thoroughly comment your code, and incorporate an informative title to your plot. Note that the fern iteration involves four conditions. Your code should make use of the elseif statement to handle these conditions. Figure 1: An example fern created with 5000 points • Problem 1 o 'unitCircle.m' • • Fully commented code Proper Indentation Correct use of for-loop Correct output plot for n = 125 • Problem 2 o'fern.m' . Fully commented code Proper indentation . Correct use of elseif statement Correct output plot Iteration is the repetition of the same process over and over again. It is a crucial programming tool that we will get some practice using this week. To get started, lets recall matrix-vector multiplication. In two dimensions, matrix-vector multiplication is computed according to the following process: which can be written simply as: where x and y are 2-by-1 vectors: and A is a 2-by-2 matrix: y(1) = A(1,1) x(1) + A(1,2) = x(2) y(2) = A(2,2) x(2) + A(2,2)=x(2) A [0 1; -1 0]; x = [1; 1]; y = A *x x=[x2], x=[2] X= y [A(1,1) A(1,2)] A(2,1) A(2,2) Let's examine the effect of iterating matrix-vector multiplication with A=1₁3 • Create a Matlab script entitled 'matVecPlot.m' to run the following code: y = A*x; plot ( [0 x(1)],[0 x(2)]); hold on plot([0 y(1)],[0 y(2)], 'r'); y = A*y; plot ( [0 y(1)], [0 (2)],"g-'); y = A*y; plot ( [@ y(1)], 10 y(2)], 'y-.'); axis equal Once you get it working, examine what the code is doing. Practice thoroughly commenting your script to describe what it does (in the header) and what each line of code is doing. Check out coinFlipping.m to see an example. Problem 1: A rotation matrix has the general form: [cos (0) (sin(0) A -sin (0)] si cos(0) where defines the angle of rotation. For example, setting = yields the matrix we employed in matVecPlot.m (try it, just to be sure). We will now use a rotation matrix to visualize the unit circle. Let's start by altering our existing script: Make sure there are no other figures open close all; % Delete all variables in the workspace clear & Value of theta that will get you around the circle in 4 iterations theta = (2*pi)/4; & Construct the rotation matrix for theta A = [cos (theta) -sin(theta); sin (theta) cos (theta)]; & Plot the initial point (iteration 1) x = [1; 1]; plot (x (1),x(2), 'b*'); hold on * Iteration 2 x = A*x; plot(x(1),x(2), 'b*') % Iteration 3 x = A*x; plot (x (1), x(2), 'b*') % Iteration 4 plot(x(1),x(2), 'b*') title('n = 4'); hold off; axis equal The above code uses only four points to visualize the unit circle. Ask yourself, how is this code different from 'matVecPlot.m'? How would one go about adjusting this code to plot 125 points on the unit circle? Generalize the above code to create a function unitCircle.m that plots n points on the unit circle (use a for-loop). Be sure to include a header, thorough comments, proper code indentation, and incorporate an informative title to your plot that includes your name. Tum in a a plot for n = 125. Problem 2: Grow a Fern In Problem 1, we used a rotation matrix to visualize the unit circle. In this problem, we will grow a fern using more general affine transformations: y = A *x + b where b is a 2-by-1 vector that "shifts" the positions of A*x. Affine transformations can encode rotation, stretching, and shifting (assuming A is invertible, but don't worry about that now), and despite their simplicity, are used in many important applications. Here's a very well-known and interesting example from brain image analysis: https://www.sciencedirect.com/science/article/pii/S1361841501000366?via%3Dihub We are going to mathematically model our fern with a fractal and use a simple Iterated Function System: https://en.wikipedia.org/wiki/lterated function system. Though I'm sure we would all greatly enjoy delving into the mathematics behind fractals, for this exercise, we only need to write a code that iteratively grows the fern. Specifically, for each iteration, your code fern.m should generate a random number and Apply x = [0 0;0 0.16]** Apply x = [0.85 0.04; -0.04 0.85]*x + [0; 1.6] Apply x = [0.2 -0.26; 0.23 0.22] *x + [0; 1.61; Apply x = [-0.15 0.28; 0.26 0.24] *x + [0; 0.44]; with probability p = 0.07 with probability p = 0.01 with probability p = 0.85 with probability p = 0.07 Initialize your iteration with x = [0; 0)] and run the iteration for n = 2750 times. Be sure to include a header, thoroughly comment your code, and incorporate an informative title to your plot. Note that the fern iteration involves four conditions. Your code should make use of the elseif statement to handle these conditions. Figure 1: An example fern created with 5000 points • Problem 1 o 'unitCircle.m' • • Fully commented code Proper Indentation Correct use of for-loop Correct output plot for n = 125 • Problem 2 o'fern.m' . Fully commented code Proper indentation . Correct use of elseif statement Correct output plot
Expert Answer:
Answer rating: 100% (QA)
Problem 1 Unit Circle Visualization unitCirclem function unitCirclen Clear existing figures and vari... View the full answer
Related Book For
Posted Date:
Students also viewed these databases questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
The Crazy Eddie fraud may appear smaller and gentler than the massive billion-dollar frauds exposed in recent times, such as Bernie Madoffs Ponzi scheme, frauds in the subprime mortgage market, the...
-
Show that 15 is an inverse of 7 modulo 26.
-
Montreal Seating Co., a manufacturer of chairs, had the following data for 2012: Sales __________________ 2,800 units Sales price _____________ $50 per unit Variable costs __________$30 per unit...
-
Verify each identity using the definitions of the hyperbolic functions. tanh(-x) = -tanh x
-
The van der Waals equation of state is given by (a) \(\left(P+\frac{a}{V} ight)(V-b)=R T\) (b) \(\left(P+\frac{a}{V^{2}} ight)(V-b)=R T\) (c) \(\left(P+\frac{a}{V^{2}} ight)(V+b)=R T\) (d) None of...
-
The normal capacity of Austin Adhesives, Inc., is 40,000 direct labor hours and 20,000 units per month. A finished unit requires 6 pounds of materials at an estimated cost of $2 per pound. The...
-
On 28th February 2020 the Competition & Markets Authority (CMA) published an update report on its investigation into Leasehold Housing. In this report the CMA stated: "The consequences of ground rent...
-
Worldwide, over a billion solder balls must be manufactured daily for assembling electronics packages. The uniform droplet spray method uses a piezoelectric device to vibrate a shaft in a pot of...
-
Read the paragraphs and give the answers. The purpose of the Myers-Briggs Type Indicator (MBTI) personality inventory is to make the theory of psychological types described by C. G. Jung...
-
What is the difficulty in applying Gauss elimination to the following linear algebraic equations? \[\begin{aligned}-10 x_{1}+10 x_{2} & =10 \\5 x_{1}-5 x_{2} & =-10\end{aligned}\]
-
1. Diagram the contingency Dawn used to help April stop her crying (Larson and Ayllon). 2. What kind of contingency is it? a. Positive reinforcement b. Negative reinforcement (escape) c. Positive...
-
Using Gauss elimination and back substitution, solve \[\left[\begin{array}{ccc}6 & 2 & 1 \\4 & 10 & 2 \\3 & 4 & 14\end{array} ight]\left[\begin{array}{l}x_{1} \\x_{2} \\x_{3}\end{array}...
-
What is meant by the term buyer behavior?
-
Determine the CT ratios for differential protection of a three-phase, \(\Delta-Y\) connected, 15-MVA, 33:11 kV transformer, such that the circulating current in the transformer \(\Delta\) does not...
-
Q3 (5 points) Suppose a contingent valuation survey was administered on a sample of 600 Lethbridge residents to estimate their willingness-to-pay (WTP) to cleanup groundwater contamination from leaky...
-
The executor of Gina Purcells estate has recorded the following information: Assets discovered at death (at fair value): Cash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....
-
Discuss with a classmate what are the most important safety considerations to address for exothermic reactions. To help answer this question, prepare a list of safety considerations for designing and...
-
The elementary reversible liquid-phase reaction takes place in a CSTR with a heat exchanger. Pure A enters the reactor. (a) Derive an expression (or set of expressions) to calculate G(T) as a...
-
Living Example 16-3 Wolfram and Python 1. Vary and find the combination of parameters for which the exit conversion is virtually the same for both early mixing and late mixing. 2. Find the...
-
What is thermodynamics?
-
An astronaut weighs \(800 \mathrm{~N}\) on the earth's surface where the acceleration of gravity is \(g=9.83 \mathrm{~m} / \mathrm{s}^{2}\). The mass and the radius of the moon are \(7.4 \times...
-
Explain the scope and limitations of thermodynamics.
Study smarter with the SolutionInn App