Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help writing this code in MATLAB. Please help me out thank you!! In this exercise, you will plot figures in xy-plane and consider

I need help writing this code in MATLAB. Please help me out thank you!!

In this exercise, you will plot figures in xy-plane and consider their images under the transformations of the plane such as reflections and shears.

**First, create two functions in MATLAB:

function VS = vrsh(k)

and

function HS = hrsh(k)

that will generate the standard matrices for the vertical and horizontal shears, respectively, defined by a parameter k. (For help, see Module 9 lecture and read Section 1.9 of the textbook.)

**Type the functions vrsh and hrsh in your diary file.

**Store on your workspace (and in your diary file) the standard matrices, which names are listed below, for the transformation indicated in the parentheses:

RX (reflection across the x-axis)

RY (reflection across the y-axis)

RO (reflection across the origin)

RS (reflection across the line y=x)

RA (reflection across the line y= -x)

For example, to store RX, type on the workspace (and save it in the diary file):

RX=[1 0; 0 -1]

and hit Enter. Do not suppress the output (no semicolon at the end).

**Next, create the following function in the file in MATLAB, which takes as inputs a 2 x 5 matrix E and a 2 x 2 matrix A. The input E is a matrix whose columns are the coordinate vectors of the vertices of a closed polygonal line, and a matrix A will be one of the standard matrices created above (VS, HS, RX, RX, RY, RO, RS, or RA)

function C = transf(A,E)

E=A*E;

x=E(1,:); y=E(2,:);

plot(x,y)

v=[-5 5 -5 5];

axis(v)

grid

C=E;

grid

end

**Type the function transf in your diary file.

% Analyze and write a short comment on each of the lines of the code for transf.

The original input E is a 2 by 5 matrix whose columns are the coordinates of the vertices of the unit square, with the first vertex at the origin the other vertices listed in the counterclockwise direction:

E = [0 1 1 0 0;0 0 1 1 0]

Part I

Now, you will start creating the first plot.

Step 1:

**Type on the workspace the initial matrix E:

E=[0 1 1 0 0;0 0 1 1 0] (Hit: Enter)

Step 2:

Apply the identity transformation in R^2 defined by eye(2) to the matrix E to have the unit square displayed on the plot. To do that:

**type

A = eye(2) (Hit Enter)

hold (Hit Enter - this command will bring up a coordinate system and will hold all your graphs)

grid (Hit Enter - this will put the grid on the coordinate system)

C = transf(A,E) (Hit Enter)

Your plot has to be the unit square whose vertices are defined by E. And the output C has to be a 2 x 5 matrix whose columns are the coordinates of the vertices of the figure that appears on the plot.

Note: The output C will be re-assigned to the matrix E every time when you perform the next consecutive transformation.

Step 3:

Now, you will modify the unit square by applying the horizontal shear with k = 2. The set of commands below will complete the task:

** type

>> E=C;

>> k=2;

>> HS = hrsh(k)

>> A=HS;

>> C=transf(A,E)

and you should receive the second figure, while the first one is held.

**Save this image as plot.jpg file on your computer and close out the plot. Insert the figure into your word document at the end of this part of the exercise.

Part II

Now, you will create a figure displayed below:

**Begin with the original matrix E. Type:

E=[0 1 1 0 0;0 0 1 1 0]

and go through Steps 1-2.

**Modify the set of commands in Step 3 to apply the vertical shear transformation with k=4 to the unit square. Then, repeat Step 3 several times, each time assigning to the matrix A one of the matrices RX, RY, RO, RS, or RA until you arrive at the figure below.

**Save this figure with the name transf.jpg and insert it into your word file for submission.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions