Extending Justin’s Guide to MATLAB in MATH 240

Extending Justin’s Guide to MATLAB in MATH 240 - Part 4
1. Method
We assume you are comfortable with (and remember or can review) commands used in the earlier
projects.
2. New Commands
(a) Eigenvalues can be found easily. If A is a matrix then:
>> eig(A)
will return the eigenvalues. Note that it will return complex eigenvalues too. So keep an i open
for those.
(b) If we have an eigenvalue λ for A, we can use rref on an augmented matrix [A λI | 0] to lead
us to the eigenvectors. For example if A is 4 × 4 and λ = 3 is an eigenvalue, then we can obtain
the coefficient matrix of this system by entering A - 3*eye(4).
(c) Even better: MATLAB can do everything in one go. If you recall from class, diagonalizing a
matrix A means finding a diagonal matrix D and an invertible matrix P with A = P DP ?1
.
The diagonal matrix D contains the eigenvalues along the diagonal and the matrix P contains
eigenvectors as columns, with column j of P corresponding to the eigenvalue in column j of D.
To do this we use the eig command again but demand different output. The format is:
>> [P,D]=eig(A)
which assigns P and D for A, if possible. If it’s not possible MATLAB returns very strange-looking
output.
(d) We can compute the dot product of two vectors using the command dot. For example:
>> dot([1;2;4],[-2;1;5])
(e) We can find the length of a vector from the basic definition. If v is a vector then:
>> sqrt(dot(v,v))
(f) Or we can just use the norm command:
>> norm(v)
(g) To get the transpose of a matrix A we do:
>> transpose(A)
or
>> A’
(h) To find the rank of a matrix A we do
>> rank(A)
(i) When A is a matrix with linearly independent columns, the command
>> [Q,R]=qr(A,0)
will create and exhibit the matrices Q, R which give the QR factorization of A as defined in the
text of Lay.
(j) MATLAB lets you define vectors and submatrices from matrices. For example, suppose A is an
m × n matrix and we enter the commands
>> F=A(1:3,2:4), G = A(1:3, :), H = A(:,2)
Then F is the 3 × 3 matrix built from entries of A in rows 1-3 and columns 2-4; G is the 3 × n
matrix built out of the first 3 rows; and H is 1 × n matrix (column vector) which equals column
2 of A.
(k) If you already have a coefficient matrix A and a vector b stored in MATLAB, then you can form
the augmented matrix M of the system Ax = b with the command
>> M = [A b]
This is useful when finding least-squares solutions. We can form the augmented matrix of the
system of normal equations AT Ax = AT b with the command
>> N = [A’*A A’*b]
3. Finding Commands

代写MATH 240作业、代做MATLAB编程语言作业、MATLAB实验作业代做、代写subspace留学生作业
If you don’t know commands to achieve a MATLAB goal, you can go back to earlier projects, or use
the help function in MATLAB. You can also guess commands and experiment to see what happens.
Just remember that the output you turn in to your T.A. should be clean and devoid of any explorations
or mistakes along the way.
4. MATLAB Help: an example
Suppose A is a 4 × 3 matrix with rank(A) = 3. As it turns out, the command
>> [Q,R]=qr(A)
produces something different from the QR factorization defined as in Lay. What’s up?
In MATLAB, I click on help; there it seems sensible to click on the function browser; then to click
mathematics; then linear algebra; then factorization. Scrolling down, I click on qr and get the news
that I need qr(A,0). (And I see a variety of qr command variants, if I want to know more.)
MATH 240 Spring 2019 MATLAB Project 4 – due in class Tuesday, 5/7
Directions:
Previous guidelines on format and collaboration hold. Please review them if you forget them. For this
project, do all problems in format short.
As before, a question part marked with a star ? indicates the answer should be typed into your output
as a comment – the question isn’t asking for MATLAB output.
0. Review all directions and rules from the previous project. Then enter the command clock
(a) Execute the command [P,D] = eig(A) to diagonalize A.
(b) Use MATLAB to verify that A = P DP ?1
.
(c) Use the previous results to give the eigenvalues of A, and give an eigenvector for each eigenvalue.
(a) Use MATLAB to compute An for n = 2, 3, 4, 5, 6, 7, 8. Do you notice a pattern?
(b) Have MATLAB produce an invertible P and a diagonal D such that A = P DP ?1
. Notice that
complex numbers get involved.
(c) To understand An, it suffices to understand Dn because An = P DnP
. Describe the pattern
that emerges when we consider powers of D: D, D2
, D3
, D4
,etc.
(d) Without doing a computation in MATLAB, determine A20000001
(a) Execute the command [P,D]=eig(A). Something strange should occur in the output.
(b) Use MATLAB to try see if A = P DP ?1
.
(c) Find a basis for the eigenspace of A corresponding to the eigenvalue λ = 3.
(d) Is there a basis for R
consisting of eigenvectors for A? Does this explain why something went
wrong in part (b) (There is a relevant theorem in §5.3.)
(a) Enter A into MATLAB and use MATLAB to compute the dot product of the first column of A
with its second column. Also compute the dot product of the third column with itself. (See guide
for how to extract a column from a matrix.)
(b) Compute the matrix product AT A.
(c) What is the relationship between the entries of AT A and the dot products of the columns of A?
Make sure your answer is consistent with your computations.
(d) What in general is the relationship between the entries of AAT and dot products of vectors
associated to A?
(e) Compute AAT and do at least two dot product computations to support your previous answer.. Do a single matrix computation which shows that the
columns of form an orthonormal set.
(g) Explain carefully why your computation above shows that the columns form an orthonormal
set.
(h Explain why the rows of Q must also form an orthonormal set.
5. Let W be the subspace of R
(a) Enter the four vectors into MATLAB as v1, v2, v3 and v4 respectively.
(b) Let A = [v1 v2 v3 v4]. Compute the rank of this matrix. Explain briefly in a comment why
this shows that this set of four vectors is a basis for W.
(c) We shall apply the Gram-Schmidt Process to produce an orthogonal basis {w1, w2, w3, w4} for
W. To begin, let w1 = v1 and w2 = v2 - (dot(w1,v2)/dot(w1,w1))*w1.
(d) Continue the Gram-Schmidt Process and compute w3 and w4.
(e) Rescale each vector of the orthogonal basis {w1, w2, w3, w4} to produce an orthonormal basis
{u1, u2, u3, u4} for W. (Recall there is a command in MATLAB to compute the norm of a
vector.)
(f) Enter the vectors u1, u2, u3, u4 into the columns of a matrix Q. Verify that the columns of Q are
orthonormal with a single matrix multiplication.
(g) Compute R = QT A. Verify that R is upper triangular with positive diagonal entries and that
A = QR.
(h) MATLAB can compute a QR factorization in a single command. Enter [Q1, R1] = qr(A,0).
Notice that there is a small discrepancy between your Q, R and the Q1, R1 produced by MATLAB.
This is because QR factorizations are not unique. They are only unique if we insist that the
diagonal entries of R are all postive. Nonetheless, the columns of Q1 still form an orthonormal
basis for W.
6. Let W be the subspace of R
6 given by
W = Span
(a) Enter those five vectors as the columns of a matrix A and compute its rank.
(b) The previous computation shows that the five vectors are linearly dependent, hence they do not
form a basis for W. Find a basis for W. (Hint: Treat W as Col A)
(c) Enter your basis for W as the columns of a matrix B. Compute the factorization B = QR with
a single command. Give an orthonormal basis for W.
(d) Let E = QQT
. As a linear transformation on R
6
, E is the orthogonal projection onto the subspace
W. Use E to compute the orthogonal projection of the vector v = (1, 1, 1, 1, 1, 1)T onto W.
(e) Find a basis for W⊥ as follows. Note that W = Col A = Col B. From a theorem in class, we have
W⊥ = (Col B)
so it suffices to find a basis for Nul(BT).
(f) As you did for W, find an orthonormal basis for W⊥.
(g) Compute the matrix F for the orthogonal projection onto W⊥. What is the sum E + F?

代写MATH 240作业、代做MATLAB编程语言作业、MATLAB实验作业代做、代写subspace留学生作业
Extending Justin’s Guide to MATLAB in MATH 240 - Part 4
1. Method
We assume you are comfortable with (and remember or can review) commands used in the earlier
projects.
2. New Commands
(a) Eigenvalues can be found easily. If A is a matrix then:
>> eig(A)
will return the eigenvalues. Note that it will return complex eigenvalues too. So keep an i open
for those.
(b) If we have an eigenvalue λ for A, we can use rref on an augmented matrix [A λI | 0] to lead
us to the eigenvectors. For example if A is 4 × 4 and λ = 3 is an eigenvalue, then we can obtain
the coefficient matrix of this system by entering A - 3*eye(4).
(c) Even better: MATLAB can do everything in one go. If you recall from class, diagonalizing a
matrix A means finding a diagonal matrix D and an invertible matrix P with A = P DP ?1
.
The diagonal matrix D contains the eigenvalues along the diagonal and the matrix P contains
eigenvectors as columns, with column j of P corresponding to the eigenvalue in column j of D.
To do this we use the eig command again but demand different output. The format is:
>> [P,D]=eig(A)
which assigns P and D for A, if possible. If it’s not possible MATLAB returns very strange-looking
output.
(d) We can compute the dot product of two vectors using the command dot. For example:
>> dot([1;2;4],[-2;1;5])
(e) We can find the length of a vector from the basic definition. If v is a vector then:
>> sqrt(dot(v,v))
(f) Or we can just use the norm command:
>> norm(v)
(g) To get the transpose of a matrix A we do:
>> transpose(A)
or
>> A’
(h) To find the rank of a matrix A we do
>> rank(A)
(i) When A is a matrix with linearly independent columns, the command
>> [Q,R]=qr(A,0)
will create and exhibit the matrices Q, R which give the QR factorization of A as defined in the
text of Lay.
(j) MATLAB lets you define vectors and submatrices from matrices. For example, suppose A is an
m × n matrix and we enter the commands
>> F=A(1:3,2:4), G = A(1:3, :), H = A(:,2)
Then F is the 3 × 3 matrix built from entries of A in rows 1-3 and columns 2-4; G is the 3 × n
matrix built out of the first 3 rows; and H is 1 × n matrix (column vector) which equals column
2 of A.
(k) If you already have a coefficient matrix A and a vector b stored in MATLAB, then you can form
the augmented matrix M of the system Ax = b with the command
>> M = [A b]
This is useful when finding least-squares solutions. We can form the augmented matrix of the
system of normal equations AT Ax = AT b with the command
>> N = [A’*A A’*b]
3. Finding Commands
If you don’t know commands to achieve a MATLAB goal, you can go back to earlier projects, or use
the help function in MATLAB. You can also guess commands and experiment to see what happens.
Just remember that the output you turn in to your T.A. should be clean and devoid of any explorations
or mistakes along the way.
4. MATLAB Help: an example
Suppose A is a 4 × 3 matrix with rank(A) = 3. As it turns out, the command
>> [Q,R]=qr(A)
produces something different from the QR factorization defined as in Lay. What’s up?
In MATLAB, I click on help; there it seems sensible to click on the function browser; then to click
mathematics; then linear algebra; then factorization. Scrolling down, I click on qr and get the news
that I need qr(A,0). (And I see a variety of qr command variants, if I want to know more.)
MATH 240 Spring 2019 MATLAB Project 4 – due in class Tuesday, 5/7
Directions:
Previous guidelines on format and collaboration hold. Please review them if you forget them. For this
project, do all problems in format short.
As before, a question part marked with a star ? indicates the answer should be typed into your output
as a comment – the question isn’t asking for MATLAB output.
0. Review all directions and rules from the previous project. Then enter the command clock
(a) Execute the command [P,D] = eig(A) to diagonalize A.
(b) Use MATLAB to verify that A = P DP ?1
.
(c) Use the previous results to give the eigenvalues of A, and give an eigenvector for each eigenvalue.
(a) Use MATLAB to compute An for n = 2, 3, 4, 5, 6, 7, 8. Do you notice a pattern?
(b) Have MATLAB produce an invertible P and a diagonal D such that A = P DP ?1
. Notice that
complex numbers get involved.
(c) To understand An, it suffices to understand Dn because An = P DnP
. Describe the pattern
that emerges when we consider powers of D: D, D2
, D3
, D4
,etc.
(d) Without doing a computation in MATLAB, determine A20000001
(a) Execute the command [P,D]=eig(A). Something strange should occur in the output.
(b) Use MATLAB to try see if A = P DP ?1
.
(c) Find a basis for the eigenspace of A corresponding to the eigenvalue λ = 3.
(d) Is there a basis for R
consisting of eigenvectors for A? Does this explain why something went
wrong in part (b) (There is a relevant theorem in §5.3.)
(a) Enter A into MATLAB and use MATLAB to compute the dot product of the first column of A
with its second column. Also compute the dot product of the third column with itself. (See guide
for how to extract a column from a matrix.)
(b) Compute the matrix product AT A.
(c) What is the relationship between the entries of AT A and the dot products of the columns of A?
Make sure your answer is consistent with your computations.
(d) What in general is the relationship between the entries of AAT and dot products of vectors
associated to A?
(e) Compute AAT and do at least two dot product computations to support your previous answer.. Do a single matrix computation which shows that the
columns of form an orthonormal set.
(g) Explain carefully why your computation above shows that the columns form an orthonormal
set.
(h Explain why the rows of Q must also form an orthonormal set.
5. Let W be the subspace of R
(a) Enter the four vectors into MATLAB as v1, v2, v3 and v4 respectively.
(b) Let A = [v1 v2 v3 v4]. Compute the rank of this matrix. Explain briefly in a comment why
this shows that this set of four vectors is a basis for W.
(c) We shall apply the Gram-Schmidt Process to produce an orthogonal basis {w1, w2, w3, w4} for
W. To begin, let w1 = v1 and w2 = v2 - (dot(w1,v2)/dot(w1,w1))*w1.
(d) Continue the Gram-Schmidt Process and compute w3 and w4.
(e) Rescale each vector of the orthogonal basis {w1, w2, w3, w4} to produce an orthonormal basis
{u1, u2, u3, u4} for W. (Recall there is a command in MATLAB to compute the norm of a
vector.)
(f) Enter the vectors u1, u2, u3, u4 into the columns of a matrix Q. Verify that the columns of Q are
orthonormal with a single matrix multiplication.
(g) Compute R = QT A. Verify that R is upper triangular with positive diagonal entries and that
A = QR.
(h) MATLAB can compute a QR factorization in a single command. Enter [Q1, R1] = qr(A,0).
Notice that there is a small discrepancy between your Q, R and the Q1, R1 produced by MATLAB.
This is because QR factorizations are not unique. They are only unique if we insist that the
diagonal entries of R are all postive. Nonetheless, the columns of Q1 still form an orthonormal
basis for W.
6. Let W be the subspace of R
6 given by
W = Span
(a) Enter those five vectors as the columns of a matrix A and compute its rank.
(b) The previous computation shows that the five vectors are linearly dependent, hence they do not
form a basis for W. Find a basis for W. (Hint: Treat W as Col A)
(c) Enter your basis for W as the columns of a matrix B. Compute the factorization B = QR with
a single command. Give an orthonormal basis for W.
(d) Let E = QQT
. As a linear transformation on R
6
, E is the orthogonal projection onto the subspace
W. Use E to compute the orthogonal projection of the vector v = (1, 1, 1, 1, 1, 1)T onto W.
(e) Find a basis for W⊥ as follows. Note that W = Col A = Col B. From a theorem in class, we have
W⊥ = (Col B)
so it suffices to find a basis for Nul(BT).
(f) As you did for W, find an orthonormal basis for W⊥.
(g) Compute the matrix F for the orthogonal projection onto W⊥. What is the sum E + F?

因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:[email protected]

微信:codinghelp

原文地址:https://www.cnblogs.com/nameptyhon/p/10840361.html

时间: 2024-10-04 10:33:21

Extending Justin’s Guide to MATLAB in MATH 240的相关文章

Windows、Linux、Web安装及调用Matlab程序完整说明(大章)

本文档详细说明了Linux下Web项目调用Matlab函数的完整操作,文章适合对Java.Linux有一定基础了解的人群(不了解也没什么,无非是多试几次).因Linux作为服务器,所以未在其上安装Matlab主程序,只安装了运行环境MCR. 本文档内所述的所有版本软件均以32位为准,JDK与MCR也使用32位.若你的系统为64位,Linux系统同样为64位,则请尽量选择使用64位版本的JDK与MCR. 由于Matlab的版本限制问题,请保证Matlab主程序和MATLABCompiler Run

Web(jsp,html)调用Matlab程序

本环节需要准备JDK和JAVA编译器以及部署项目服务器,本节使用Eclipse和Tomcat. 1.  创建web工程,工程中需要引入javabuild.jar和Matlab函数的JAR包,直接放到lib里 2.  下面进行对Matlab函数Math.jar进行调用,分2种方式,本文仅作简单测试,并不搭建web框架进行传地址. 3.  使用JSP测试调用sum2.jar中封装对象,测试函数输出结果. A 创建jsp页面,在jsp页面头部文件引用包 <%@ page language="ja

第一章读书笔记--关于View

Chapter1 Views Chapter1 Views The Window Experimenting With Views Subview and SuperView 可见性和透明度Visibility and Opacity Frame Bounds and Center 窗口坐标和屏幕坐标 Transform Trait Collection and Size Classes Layout 1 Autoresizing 2 AutoLayout 21 Constraints 22 A

【原创】开源Math.NET基础数学类库使用(三)C#解析Matlab的mat格式

开源Math.NET系列文章目录: 1.开源.NET基础数学计算组件Math.NET(一)综合介绍  2.开源.NET基础数学计算组件Math.NET(二)矩阵向量计算  3.开源.NET基础数学计算组件Math.NET(三)C#解析Matlab的mat格式 4.开源.NET基础数学类库使用Math.NET(四)C#解析Matrix Marke数据格式 5.开源.NET基础数学类库使用Math.NET(五)C#解析Delimited Formats数据格式 6.开源.NET基础数学类库使用Mat

开源Math.NET基础数学类库使用(03)C#解析Matlab的mat格式

原文:[原创]开源Math.NET基础数学类库使用(03)C#解析Matlab的mat格式 开源Math.NET基础数学类库使用系列文章总目录:   1.开源.NET基础数学计算组件Math.NET(一)综合介绍   2.开源.NET基础数学计算组件Math.NET(二)矩阵向量计算   3.开源.NET基础数学计算组件Math.NET(三)C#解析Matlab的mat格式   4.开源.NET基础数学类库使用Math.NET(四)C#解析Matrix Marke数据格式   5.开源.NET基

Matlab学习-----------GUIDE菜单学习

打开GUIDE,添加组件,然后点击菜单编辑按钮: 编辑菜单和子菜单,包含快捷键,label和tag,然后点击View编辑菜单的回调函数: 为按钮添加回调函数,程序如下: function varargout = guide_menu(varargin) % GUIDE_MENU MATLAB code for guide_menu.fig % GUIDE_MENU, by itself, creates a new GUIDE_MENU or raises the existing % sing

Matlab中所有自定义的函数

Functions By Category | Alphabetical List Language Fundamentals Entering Commands ans Most recent answer clc Clear Command Window diary Save Command Window text to file format Set display format for output home Send cursor home iskeyword Determine wh

(转) A Survival Guide to a PhD

A Survival Guide to a PhD Sep 7, 2016 This guide is patterned after my “Doing well in your courses”, a post I wrote a long time ago on some of the tips/tricks I’ve developed during my undergrad. I’ve received nice comments about that guide, so in the

(转)A Beginner&#39;s Guide To Understanding Convolutional Neural Networks

Adit Deshpande CS Undergrad at UCLA ('19) Blog About A Beginner's Guide To Understanding Convolutional Neural Networks Introduction Convolutional neural networks. Sounds like a weird combination of biology and math with a little CS sprinkled in, but