ENSC 180: Introduction to Engineering Analysis

Assignment 4

Note: MATLAB codes should include definition of all variables; headings to identify

the program structure plan; and appropriate captions and labels for tables and

figures. Submit a .pdf report documenting your inputs and outputs in addition to a

separate zip-file containing all M-files. Marks will be deducted for solutions that are

unrealistic/impractical (as future engineers students should learn to think practically)

and poorly documented.

1. Given [A]= [4 3 1;3 7 -1; 1 -1 9], [B]= [10 8 7; 3 -3 0; 14 1 7] and [C]= [1 -1; 4 7;

9 5]. Using MATLAB built-in functions, write a script or use the command line to

perform the following operations and print out the resulting matrices.

(a) A+B (b) A*C (c) AT

(d) AAT

(e) CCT

(f) A-1B

-1

(g) rank of A and C (h)

determinant of A (i) solve the equation system [A]{x} =[C]. (20 marks)

2. Write a user-defined function to add and multiply two matrices without using the

MATLAB matrix-wise + and * operations. The function should have the two

matrices as input, check whether the addition and multiplication operations are

valid for the given matrices and if valid, manually compute the operation (using

for-loops) and present the output matrix. If the operations are not valid, the

function should print a statement to that effect. Print out the results of the function

using inputs [A],[B], [A],[C] and [C],[A]. (20 marks)

3. Find the determinant of ([A]-α[I]) algebraically without using MATLAB, where

[A] is given in Q1 above, I is an identity matrix and α is a scalar. Solve the

equation det([A]-α[I]) =0 to find the values of α by plotting the equation using

MATLAB over the range 0 ≤α ≤10. Display the plot and values of α .(20 marks)

4. Write a MATLAB code to perform Gauss elimination for a general system of form

[A]{x} = {b}. Assume [A] is a real square matrix and {b} is also real. Your code

should determine whether the rank of [A] is less than the size of [A] based on the

results of Gauss elimination and decide the next step. Use your code to solve Q1(i).

(40 marks)