Sie sind auf Seite 1von 4

Matlab Assignment 1

CHEMICAL ENGINEERING I

2011-12

1. Use the magic command to construct and print out a matrix A R55 with the two properties: the 25 elements of A are precisely the integers 1 25;

the elements of each row, column and principal diagonal of A sum to 65. Then use Matlab commands to print out the answers to the following questions. (a) Sum the elements in each column of A and store the result in S1 R15 . (c) Use the diag command to sum the elements in the NW SE diagonal.

(b) Sum the elements in each row of A and store the result in S2 R51 .

(d) Use the flipud command to sum the elements in the NE SW diagonal.

(e) Construct 7 dierent 5 5 magic squares from A by using the rot90 command and the transpose operation. (The total number of dierent 55 magic squares is known to be 275305224; but the corresponding result for 6 6 matrices is unknown.) (f) Construct the 5 3 matrix B1 consisting of the rst, second and fth columns of A.

(g) Construct the 3 5 matrix B2 consisting of the second, third and fth rows of A. (h) Construct the 3 3 matrix B3 consisting of the rst, third, fth rows and columns of A. (i) Find the maximum and minimum values in each column of A; also the row component numbers which produce these values. (j) Find the maximum and minimum values in each row of A; also the column component numbers which produce these values. (k) Sort each row in ascending order and store the result in C1 R55 . (l) Sort each column in descending order and store the result in C2 R55 .

(m) Construct a new matrix C3 R55 by replacing each element a A according to the following rule log(a) : a 13 a 1 : a 12 13a (n) Print out the row/column numbers for those elements a A which satisfy a 12. (Make sure you display the row/column numbers as pairs.)

2. (a) Set up the 4 4 matrix

in Matlab, and use the rank and det commands to compute and print out the rank of A and its determinant. Use the null command to obtain a solution of AT y = 0 and store this result in the Matlab column vector b. (Note that any scalar multiple of b is also a solution of this system of equations.) (b) Use the while command to determine the rst value of p (call it p) for which rank(Ap ) = 3, where Ap A + 10p e3 eT 3 Note that 0 0 e3 1 0 p p = 0, 1, 2, . . .. 0 0 e3 eT 3 0 0 0 0 0 0 0 0 1 0 0 0 . 0 0

1 2 3 4 5 6 7 8 A= 9 10 11 12 13 14 15 17

and so

Use the cond command to print out the table rank(Ap )


1 cond(Ap )

p = 0, 1, 2, . . . p

with the format short g. ([cond(Ap )]1 tells you how close Ap is to being a singular matrix, so you should see this number decreasing as p increases.) (c) Use the Matlab \ operator to solve Ap x = b p = 0, 1, 2, . . . , p.

Store the results in the 3 (p + 1) matrix X and use the format short g to display XT . (d) Set up the 5 3 matrix 1 6 2 7 3 8 4 9 5 10 11 12 13 14 15

in Matlab and use the rank command to check that rank(B) = 2. (e) Use the while command to determine the rst value of p (call it p) for which rank(Bp ) = 2, where Bp B + 10p e4 eT 2 2 p = 0, 1, 2, . . ..

B=

Note that

Use the cond command to print out the table p rank(Bp )


1 cond(Bp )

0 0 e4 eT 0 2 0 0

0 0 0 1 0

0 0 0 . 0 0

p = 0, 1, 2, . . . p

with the format short g. ([cond(Bp )]1 tells you how close Bp is to being a matrix of rank = 2, so you should see this number decreasing as p increases.) (f) Use the Matlab \ operator to solve Bp x = e where e 1 1 1 1 1 p = 0, 1, 2, . . . , p,
T

(Of course, since there are more equations than unknowns, Matlab provides the best attempt at a solution.) Store the results in the 3 (p + 1) matrix Y and use the format short g to display YT . 3. The famous Hermite polynomials {Hn (x)} of degree n 0 can be constructed from the three-term recurrence formula Hn+1 (x) = 2xHn (x) 2nHn1 (x) with H0 (x) 1 and H1 (x) 2x. (a) Use the three-term recurrence formula to calculate the Matlab array representations for H1 (x) up to H5 (x) and to print out the coecients of these polynomials. (b) The values of Hermite polynomials rapidly become large in size; thus it is convenient to introduce the normalised polynomials H dened by Hn (x) = 1 Hn (x) 2n n!
5

n1

n = 0, 1, . . ..

Plot the ve polynomials Hn (x) n=1 for x [2.5, 2.5] on the same graph; using polyval to evaluate the polynomials and using enough points to obtain smooth curves. The dierent curves should be distinguished by colour and/or linestyle. (c) Use the roots command to nd the roots of Hn (x) n=1 and the sort command to put them into ascending order. Print out these roots and verify that they are all real, distinct and symmetric about x = 0. 3
5

(d) Use the polyder command to construct the Matlab array representations for H1 (x) up to H5 (x). Print out the coecients of these polynomials. Deduce a formula connecting Hn with Hn1 for n = 1, . . . , 5. (e) Construct the 6 6 symmetric tridiagonal matrix T with zeroes on the principal diagonal and elements { k/2}5 on the neighbouring diagonals. (The k=1 neatest Matlab method for doing this is to use the spdiags command and then the full command.) Use the eig command to display the eigenvalues of T and the 6 6 matrix of eigenvectors. Verify that the eigenvector matrix is orthogonal by multiplying it by its transpose. (f) Divide each column of the eigenvector matrix by its corresponding rst element, so that each eigenvector is now normalised so that its rst element is 1. Print out the new eigenvectors, verifying that Tu = u still holds for each eigenvalue and corresponding new eigenvector u. (g) Find the roots of H6 (x) and print them in ascending order. You should see a connection between these roots and the eigenvalues in (e). If these roots are denoted {xj }6 , calculate and display the 6 6 matrix with elements j=1 Hi1 (xj ) i = 1, . . . , 6; j = 1, . . . , 6.

You should see a connection between this matrix and the nal eigenvector matrix in (f). 4. Use the commands besselj and bessely to plot the Bessel functions J0 (x) and Y0 (x) on the same graph for the range 0.1 x 10. (We keep away from x = 0 because Y0 is unbounded there.) Using the fact that the nth positive zeroes of 3 J0 (x) and Y0 (x) can be estimated by (n 1 ) and (n 4 ) respectively, use these 4 numbers as starting values for the root-nder fzero in order to locate the rst 10 positive roots of both J0 and Y0 . (Check that nothing goes wrong by looking at your graphs.) Thus you should display two 10 1 arrays, J0zero and Y0zero say, which contain the required zeroes.

As explained in the rst chapter of the notes, you should publish your Matlab input/output as a Word document. Extra textual explanation can then be added before you submit it as a pdf le. The submission date for groups 2 & 3 is Thursday 24th November, and for groups 1 & 4 it is Thursday 8th December.

Das könnte Ihnen auch gefallen