Matrix Calculations with MATLAB: Properties and Practice Problems, Exams of Aerospace Engineering

Introductory examples and solutions for matrix calculations using matlab, including verifying matrix properties such as symmetry and determinant. It also includes practice problems for calculating transposes, cross products, and matrix multiplication.

Typology: Exams

Pre 2010

Uploaded on 03/10/2009

koofers-user-36q
koofers-user-36q 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Getting started with MATLAB
Written by Burak Ozturk
Last revision: January 18, 2001
Some introductory example problems with solutions:
To start, let’s see how some simple matrix calculations are performed using MATLAB.
Verify the following matrix properties:
1. If [A] is symmetric, the matrix [D] = [A] [B] is, in general, not symmetric, even
if [B] is also symmetric.
2. If [A] is symmetric, the matrix [D] = [B]T [A] [B] is always symmetric.
3. If [A] [B] = [C] [B], it does not necessarily follow that [A] = [C].
4. If [D] = [A] [B], then [D] T = [B] T [A] T
5. det [A] = Π λj where λj is the j-th eigenvalue of [A] (Use help in MATLAB to
see the commands det, prod, eig)
Answers:
Prob 1:
>> A=[2 4 1;4 8 2;1 2 3]
A =
2 4 1
4 8 2
1 2 3
>> B=[4 6 3;6 1 2;3 2 8]
B =
4 6 3
6 1 2
3 2 8
>> D=A*B
D =
35 18 22
70 36 44
25 14 31
% A and B are both symmetric matrices, where their product, which is D,
% is not a symmetric matrix.
Prob 2:
pf3
pf4
pf5

Partial preview of the text

Download Matrix Calculations with MATLAB: Properties and Practice Problems and more Exams Aerospace Engineering in PDF only on Docsity!

Getting started with MATLAB

Written by Burak Ozturk

Last revision: January 18, 2001

Some introductory example problems with solutions:

To start, let’s see how some simple matrix calculations are performed using MATLAB.

Verify the following matrix properties:

1. If [A] is symmetric, the matrix [D] = [A] [B] is, in general, not symmetric, even

if [B] is also symmetric.

2. If [A] is symmetric, the matrix [D] = [B] T^ [A] [B] is always symmetric.

3. If [A] [B] = [C] [B], it does not necessarily follow that [A] = [C].

4. If [D] = [A] [B], then [D] T^ = [B] T^ [A] T

5. det [A] = Π λj where λj is the j-th eigenvalue of [A] (Use help in MATLAB to

see the commands det, prod, eig)

Answers: Prob 1:

A=[2 4 1;4 8 2;1 2 3] A = 2 4 1 (^41 82 )

B=[4 6 3;6 1 2;3 2 8] B = (^46 61 ) 3 2 8 D=A*B D = (^3570 1836 ) 25 14 31 % A and B are both symmetric matrices, where their product, which is D,% is not a symmetric matrix.

Prob 2:

% Using the same matrices A and B from the problem 1.1;

D=B'AB D = (^635330 330172 ) 445 238 402 % The matrix D=B'AB is symmetric.

Prob 3:

B=[0 0;0 0];>> A=[1 2;3 2]; C=[4 4;5 2]; AB ans = 0 0 0 0 CB ans = (^00 )

% Here, AB=CB, although A and C are different matrices.

Prob 4:

A=[5 7;3 2];>> B=[1 3;4 4]; D=A*B; A = (^53 )

B = (^14 )

D = 33 11 4317

D' ans =

% B= any matrix of size m x n % Output variable: % A= a matrix of size n x m [m n]=size(B); for i=1:mfor j=1:n

end A(j,i)=B(i,j); end

% Now we are going to check the function where we let it operate on a % random matrix B of size 4x6. % >> B=rand(4,6) % B = %% 0.95010.2311 0.89130.7621 0.82140.4447 0.92180.7382 0.93550.9169 0.05790. % 0.6068 0.4565 0.6154 0.1763 0.4103 0. % 0.4860 0.0185 0.7919 0.4057 0.8936 0. % >> [A]=newtransp(B) % A = %% 0.95010.8913 0.23110.7621 0.60680.4565 0.48600. % 0.8214 0.4447 0.6154 0. %% 0.92180.9355 0.73820.9169 0.17630.4103 0.40570. % 0.0579 0.3529 0.8132 0.

% You can see that the output matrix A is the transpose of the % input matrix B. The function operates correctly.

2. Compute the cross product: Write a function called “crossprod” to compute the

cross product of two vectors u, v , given u = (u 1 , u 2 , u 3 ), v=(v 1 , v 2 , v 3 ). Check your

function by taking cross products of pairs of unit vectors: (i,j), (j, k), etc.

i={1, 0, 0}T, j={0, 1, 0}T, k={0, 0, 1}T.

You can also test your function using the MATLAB built-in function “cross”

here.

Answer:

function [w]=crossprod(u,v) % Input variables % Two vectors u=(u1,u2,u3) and v=(v1,v2,v3) % Output variable is the vector w=(w1,w2,w3), which is the cross % product of the vectors u,v. w(1,1)=u(2,1)v(3,1)-u(3,1)v(2,1); w(2,1)=u(3,1)v(1,1)-u(1,1)v(3,1);w(3,1)=u(1,1)v(2,1)-u(2,1)v(1,1);

% Now we want to check the function by taking cross products of pairs% of unit vectors.

%% >> i=[1;0;0];>> j=[0;1;0]; % >> k=[0;0;1];

% >> [w]=crossprod(i,j) % w = %% (^00) % 1 % The output vector w is equal to the unit vector k=[0;0;1], which % shows that the function works correctly.

% Similarly; % >> [w]=crossprod(j,k) % w = % 1 %% (^00)

% >> [w]=crossprod(i,k) % w = % 0 %% -1 0

% Now we call the function;

[P]=matmul(K,d) P = 148 129 142 56 flops ans = 24

% For checking purposes, we simply calculate the product of our two % matrices K and d.

K*d ans = (^148142 )

flops ans = 24 % Multiplying a 2x3 matrix K with a 3x2 matrix d resulted in a 2x2% matrix P, as expected.

% The result we get using the program we wrote and the result we get by% simply multiplying the two matrices K and d are the same. So the % program works correctly and also in a most efficient way by % performing 24 flops, which is exactly the same number of flops the% MATLAB built-in arithmetic operation uses to perform the same % calculation.