Docsity

MATH2605 Homework 4: Matlab Scripting, Symbolics, Eigenvalues, and Nonlinear Surfaces, Assignments of Mathematics

Toggle sidebar
bg1
[MATH2605] Homework 4
Feb. 2 - Feb. 9
Problem 1: Matlab Practice #2
We will learn writing matlab scripts and using symbolics. Answer or do questions with ∗.
1. Try pwd. This will show you the current working directory. You can use cd command to move to any other
directory. You may create a matlab directory in your home directory and move to there.
2. Matlab script is a text file with extension ’m’. Try edit test1.m. This will open the matlab editor with a file
”test1.m”. You can write any matlab command and save the script file. You can execute this script by test1.
∗From internet or matlab help, can you find whether this script is interpreted or compiled?
3. Try help function.∗Create a script that takes a matrix, and compute and return the largest and smallest eigenval-
ues. You may submit hand-written (or printed) copy of the script.
4. We now try symbolics. This will allow you to compute partial derivatives quickly. Try syms x y real;. This will
declare real variables xand y.
5. Define a function f(x,y)by f = (3*(1+x)ˆ2 + x*yˆ3+yˆ2) / (1+xˆ2+yˆ2).
6. Try help sym/diff and read help. ∗What is the command that computes ∂f
∂xand ∂f
∂y?
7. Try help pretty and read help. Try help simplify and read help. ∗Using the simplify and pretty commands,
compute and submit the simplified forms of ∂f
∂xand ∂f
∂y?
8. ∗What are the commands that compute ∂
∂y
∂f
∂xand ∂
∂x
∂f
∂y?
∗Is ∂
∂x
∂f
∂y=∂
∂y
∂f
∂xtrue?
Problem 2
Last week, we have computed eigenvalues and eigenvectors of the two matrices A=
−122
−121
−223
, and B=
1 4 3
−786
2 2 3
.
The matrix Ahas eigenvalues {1,1,2}, where 1 is the eigenvalue with multiplicity 2 that has two linearly independent
eigenvectors. In contrast, Bhas eigenvalues {3,3,6}, where 3 is the eigenvalue with multiplicity 2, but it has only one
linearly independent eigenvector.
Note that Ahas three linearly independent eigenvectors: two associated with 1 and another associated with 2. There-
fore, we can construct an invertible eigenvector matrix VAand the diagonal eigenvalue matrix DAso that AVA=VADA.
Since VAis invertible, we can right multiply V−1
Ato obtain an eigenvalue decomposition A=VADAV−1
A. Since DAis
diagonal, we say Ais diagonalizable.
However, even though we can construct an eigenvector matrix VBand the diagonal eigenvalue matrix DBso that
BVB=VBDB, the eigenvector matrix VBis not invertible. There are only two eigenvectors: one associated with 3 and
1
pf2

Partial preview of the text

Download MATH2605 Homework 4: Matlab Scripting, Symbolics, Eigenvalues, and Nonlinear Surfaces and more Assignments Mathematics in PDF only on Docsity!

[MATH2605] Homework 4

Feb. 2 - Feb. 9

Problem 1: Matlab Practice # 2

We will learn writing matlab scripts and using symbolics. Answer or do questions with ∗.

  1. Try pwd. This will show you the current working directory. You can use cd command to move to any other directory. You may create a matlab directory in your home directory and move to there.
  2. Matlab script is a text file with extension ’m’. Try edit test1.m. This will open the matlab editor with a file ”test1.m”. You can write any matlab command and save the script file. You can execute this script by test. ∗From internet or matlab help, can you find whether this script is interpreted or compiled?
  3. Try help function. ∗Create a script that takes a matrix, and compute and return the largest and smallest eigenval- ues. You may submit hand-written (or printed) copy of the script.
  4. We now try symbolics. This will allow you to compute partial derivatives quickly. Try syms x y real;. This will declare real variables x and y.
  5. Define a function f ( x , y ) by f = (3*(1+x) ˆ 2 + x*y ˆ 3 + y ˆ 2) / (1+x ˆ 2+y ˆ 2).
  6. Try help sym/diff and read help. ∗What is the command that computes ∂ ∂^ fx and ∂ ∂^ yf?
  7. Try help pretty and read help. Try help simplify and read help. ∗Using the simplify and pretty commands, compute and submit the simplified forms of ∂ ∂^ xf and ∂ ∂^ fy?
  8. ∗What are the commands that compute (^) ∂∂ y^ ∂ ∂^ xf and (^) ∂∂ x^ ∂ ∂^ fy? ∗Is ∂ ∂ x

∂ f ∂ y =^

∂ ∂ y

∂ f ∂ x true?

Problem 2

Last week, we have computed eigenvalues and eigenvectors of the two matrices A =

, and B =

The matrix A has eigenvalues { 1 , 1 , 2 }, where 1 is the eigenvalue with multiplicity 2 that has two linearly independent eigenvectors. In contrast, B has eigenvalues { 3 , 3 , 6 }, where 3 is the eigenvalue with multiplicity 2, but it has only one linearly independent eigenvector.

Note that A has three linearly independent eigenvectors: two associated with 1 and another associated with 2. There- fore, we can construct an invertible eigenvector matrix V A and the diagonal eigenvalue matrix D A so that AV A = V A D A. Since V A is invertible, we can right multiply V − A^1 to obtain an eigenvalue decomposition A = V A D A V − A^1. Since D A is diagonal, we say A is diagonalizable.

However, even though we can construct an eigenvector matrix V B and the diagonal eigenvalue matrix D B so that BV B = V B D B , the eigenvector matrix V B is not invertible. There are only two eigenvectors: one associated with 3 and

another associated with 6. We cannot construct a full rank, and therefore invertible, matrix V B. Therefore, we cannot have the eigenvalue decomposition B = V B D B V − B^1 , with a diagonal matrix D B. We say that B is not diagonalizable.

In fact, if allow an off-diagonal term in D B , we can make B = V B D B V − B^1. We can compute this by using the Matlab command jordan. Using this command, compute V B and D B and submit the matrix. Also verify that B = V B D B V − B^1. Note that D B is not a diagonal matrix anymore. This is called the Jordan decomposition.

Problem 3

Using Matlab, we can plot graphs of nonlinear surfaces. Try help meshgrid , and read some. Try [X,Y] = meshgrid(-3:0.2:3, -3:0.2:3);. This will create an array X that varies along rows and Y that varies through columns.

Now, construct a function f ( x , y ) = x^2 + y^2 / 4 + 3 xy + 2, by f = X.X + Y.Y/4 + 3X.Y + 2. You can plot the surface by surf(X,Y,f); xlabel(’x’); ylabel(’y’); zlabel(’f’);. Submit a hand-drawn sketch (or printed copy) of this graph.

The contour can be plotted by contour(X,Y,f,-40:4:40). Submit a hand-drawn sketch (or a printed copy) of this contour graph. What each curves in this contour plot stands for?

The gradient of f ( x , y ) is ∇ f = [ 2 x + 3 y y / 2 + 3 x ] T^. Compute the gradient by fx = 2X + 3Y; fy = Y/2 + 3*X;. The gradient vector can be drawn by quiver(X,Y,fx,fy);

You can draw the contour and the gradient vectors together by using the ’hold’ command. Try contour(X,Y,f,-40:4:40); axis equal; xlabel(’x’); ylabel(’y’); hold on; quiver(X,Y,fx,fy); hold off; What is the angle between the gradient vector and the contour line?

Critical point is the point where ∇ f = 0. Compute the critical point. Indicate the critical point in your contour graph.