Question

2.1 Summary In this part, you will create a figure, and use linear transformations (matrices) to move the figure around the s
You can then use this function in your script by using the command plot-points(P) Where P is the matrix created above. (It wi
2.6 Translate to Origin Create a matrix that represents the following transformation Tenter((r, y,, y- cy,) Where ccy are the
2.1 Summary In this part, you will create a figure, and use linear transformations (matrices) to move the figure around the screen. In the end, your figure should move up 8 steps, then turn and face left. Reference material for this part can be found in Linear Algebra, and its applications, David Lay, Section 2.7 starting at the beginning of the section up to, but not incluing,3D Graphics. Also, this poster presentation does a pretty good job explaining the same concepts http://web.csulb.edu/~jchang9/m247/m247sp12 Daniel Kris James.Walter.pdf 2.2 Create Figure in Plane Recreate the image below by creating a matrix whose first row is the x-coordinates of the vertices in clockwise order, and whose second row are the corresponding y-coordinates. Place the following function at the bottom of your script to plot the points in the matrix function plot-points(points) figure(1) fill (points(1,), points(2, . ' set (gca, 'color', [o, o, o): axis ([-10, 10, -10, 10]); end
You can then use this function in your script by using the command plot-points(P) Where P is the matrix created above. (It will look a bit different than shown). 1.8 1.6 1.2 08 0.4 02 1 08 06 04 02 02 04 08 8 2.3 Homogeneous Coordinates Convert the points stored in your matrix to homogeneous coordinates by adding a row of all ones to the bottom of your matrix of coordinates. 2.4 Translation Create a matrix that represents the following transformation i.e. Translation in the y direction by one unit. You can test that you have the correct matrix by applying the transformation to each column in the matrix of homogeneous coordinates and then plotting the new points using the function from above. Use a for-loop to apply this transformation 8 times and plot the result each iteration using the function from part 1 2.5 Find Center Write a function (at the bottom of your script) that will compute the center of your figure The x-coordinate of the center is just the average of each of the x-coordinates (of the vertices) similarly the y-coordinate of the center is the average of each of the y-coordinates. You should be able to use the function in the following way [centerx, center-y] -FindCenter (P) Where P is the matrix of homogeneous coordinates.
2.6 Translate to Origin Create a matrix that represents the following transformation Tenter((r, y,, y- cy,) Where ccy are the coordinates of the center found in the previous part. You can test that you have the correct matrix by applying the transformation to each column in the matrix of homogeneous coordinates and then plotting the new points using the function from part 1 you should see the figure move to be centered at the origin. Comment out any tests, before moving on to the next section 2.7 Rotation Create a matrix (Linear Transformation) that has the effect of rotating the figure by 90 Apply the following transformation to each of the columns in the matrix of homogeneous coordinates and then plot the new points: center Too Toenter Aside: Check what happens if only Too is used. The above transformation is used so that the center is kept in the same place 2.8 Bonus Make the figure travel in a complete square
0 0
Add a comment Improve this question Transcribed image text
Answer #1

MATLAB CODE:

For conjugate gradient method
clear all
close all

%Running the program with given parameters
%All A, x0, b and epsilon values

A=[4 3 0;3 4 -1;0 -1 4];
b=[2;1;0];
epsi=10^-8;
x0=[0;0;0];

fprintf('Example code for Conjugate gradient \n')
fprintf('The A matrix is \n')
disp(A)

fprintf('The b matrix is \n')
disp(b)


x=x0;
r_old=b-A*x;
p=r_old;
epsi=epsi*norm(r_old);
cnt=0;

%loop for conjugate gradient method
while norm(r_old)>epsi
  
    cnt=cnt+1;
    alpha=(r_old'*r_old)/(p'*A*p);
    x=x+alpha*p;
    r_new=r_old-alpha*A*p;
    beta=(r_new'*(r_new-r_old))/(r_old'*r_old);
    p=r_new+beta*p;
    r_old=r_new;
  
end

fprintf('The solution matrix using manual code is \n')
disp(x)

%Running the program with conjugate gradient function
[x,iter]=conjugategradient(A,x0,b);

fprintf('The solution matrix using conjugategradient function is \n')
disp(x)

fprintf('Error in conjugate gradient method is %e.\n',norm(x-A\b))

%Running program for iteration count
r=4;
fprintf('\nSolution using conjugate gradient method for different n.\n')

for i=1:6
  
    n=2^(r+i);
    %creating tridiagonal matrix A
    A=full(gallery('tridiag',n,-1,2,-1));
    %considering exact solution value as 1
    x=ones(n,1);
    %creating b vector of length n
    b=A*x;
    %initial guess
    x0=zeros(n,1);
  
    %finding solution using conjugategradient solution
    [x1,iter]=conjugategradient(A,x0,b);
    fprintf('\tFor n=2^%d the iteration count is %d.\n',(r+i),iter)
    fprintf('\tError in conjugate gradient method is %e.\n\n',norm(x1-A\b))
  
end
  
  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%Function for Conjugate Gradient method
function [x,iter]=conjugategradient(A,x0,b)
    epsi=10^-8;
    x=x0;
    r_old=b-A*x;
    p=r_old;
    epsi=epsi*norm(r_old);
    cnt=0;
    while norm(r_old)>epsi

        cnt=cnt+1;
        alpha=(r_old'*r_old)/(p'*A*p);
        x=x+alpha*p;
        r_new=r_old-alpha*A*p;
        beta=(r_new'*(r_new-r_old))/(r_old'*r_old);
        p=r_new+beta*p;
        r_old=r_new;

    end
    iter=cnt;
end

Add a comment
Know the answer?
Add Answer to:
2.1 Summary In this part, you will create a figure, and use linear transformations (matrices) to ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2.1 Summary In this part, you will create a figure, and use linear transformations (matrices) to ...

    2.1 Summary In this part, you will create a figure, and use linear transformations (matrices) to move the figure around the screen. In the end, your figure should move up 8 steps, then turn and face left. Reference material for this part can be found in Linear Algebra, and its applications David Lay, Section 2.7 starting at the beginning of the section up to, but not including, 3D- Graphics. Also, this poster presentation does a pretty good job explaining the...

  • For this project, each part will be in its oun matlab script. You will be uploading a total 3 m f...

    For this project, each part will be in its oun matlab script. You will be uploading a total 3 m files. Be sure to make your variable names descriptive, and add comments regularly to describe what your code is doing and hou your code aligns with the assignment 1 Iterative Methods: Conjugate Gradient In most software applications, row reduction is rarely used to solve a linear system Ar-b instead, an iterative algorithm like the one presented below is used. 1.1...

  • linear algebra Remember we were able to express rotations and reflections, which are geometric transformations, using...

    linear algebra Remember we were able to express rotations and reflections, which are geometric transformations, using a linear transformation T, the coef- ficient matrix corresponding to the geometric transformation (r. y) (r', ) (a) What problem do you encounter with translations (r. y) (r+ h.y+k)? To handle this problem, We let the vector (x, y1 ) in R2 correspond to the vector (x1, y1, 1), and conversely. (In effect, we're projecting the :xy-plane onto the plane 1) introduce homogeneous coordinates....

  • Example 1: Least Squares Fit to a Data Set by a Linear Function. Compute the coefficients of the ...

    Example 1: Least Squares Fit to a Data Set by a Linear Function. Compute the coefficients of the best linear least-squares fit to the following data. x2.4 3.6 3.64 4.7 5.3 y| 33.8 34.7 35.5 36.0 37.5 38.1 Plot both the linear function and the data points on the same axis system Solution We can solve the problem with the following MATLAB commands x[2.4;3.6; 3.6;4.1;4.7;5.3]; y-L33.8;34.7;35.5;36.0;37.5;38.1 X [ones ( size (x)),x); % build the matrix X for linear model %...

  • A unit cube as shown in Figure Q1 is undergoing the transformations described in (i) and...

    A unit cube as shown in Figure Q1 is undergoing the transformations described in (i) and (ii) respectively. Sketch the resultant object with coordinates of each vertex after each transformation. (a) Z (0,1,1) (1,1,1) (0,0,1) (1,0,1) (0,0,0) (1,1,0) (1,0,0) Figure Q1 Transformation (i) (6 marks) 1. A Uniform scale by a factor of 2 2. Followed by a rotation about the-axis in counter-clockwise direction by 90 degrees 3. Followed by a transformation moving in the direction of < 2, 1,...

  • In this exercise, you will create a function trough_plot which will plot the cross-section of a...

    In this exercise, you will create a function trough_plot which will plot the cross-section of a trough outlines by the functions y0 and y. Input variables: x – a vector representing the x co-ordinates for the outline of the trough. y – a vector representing the y co-ordinates for the bottom of the trough. y0 – a vector representing the y co-ordinates for the top of the trough. Output variable: n/a – this function has no output variables. Process: The...

  • 1. Construct affine linear transformations to do the following to the square in Figure 4.la (a) R...

    please do the number 2 1. Construct affine linear transformations to do the following to the square in Figure 4.la (a) Rotate the square 180° counterclockwise around the origin (in the plane) width. unchanged) (b) Move the square 7 units to the right, 3 units up, and double its (c) Make the vertical lines of the square slant at a 45 angle (height (d) Reflect the square about the y-axis. u Au + b, giving A and b. 4.la for...

  • You may use a calculator and/or computer to carry out calculations. However you must show a...

    You may use a calculator and/or computer to carry out calculations. However you must show a sufficient amount of work to clearly communicate your solution to the reader. [A] Consider the L-shaped polygon with vertices: (-1,0), (1,0), (1,1), (0,1), (0,3), and (-1,3) shown to the right. Find the standard matrix for each of the transformations described below. Then use matrix multiplication to obtain the coordinates for the 6 vertices that result from applying the transformation to the vertices of the...

  • c++ help please! Create a 2D character array in your main function and use nested for...

    c++ help please! Create a 2D character array in your main function and use nested for loops to fill the array with the letter ‘e’ to represent empty spaces. Create a function to print the board on the screen using a nested for loop. The function header is: void printBoard (char board [][3]) Create a function that checks whether a particular space has already been filled. If the space is filled it returns a boolean value of true, otherwise false....

  • MATLAB Any guidance is appreciated! Use meshgrid() function to create 2D grid coordinates with x- and...

    MATLAB Any guidance is appreciated! Use meshgrid() function to create 2D grid coordinates with x- and y- coordinates both from -12 to +12 in the increment 1/32. B) Calculate the function z shown below at every (x, y) point and store the result in a 2D array z Z = sin(squareroot x^2 + y^2)/ squareroot x^2 + y^2 c) Find the maximum value in array z and its corresponding index. The array may have more than one maximum points with...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT