Description
Assignment #1
Objective
This assignment is designed to provide you with an introduction to MATLAB. You will create your own M-file to perform some basic matrix manipulations, and write a program to calculate mortgage interest.
Marking Scheme
This assignment is worth 3% of your final mark. You will get a total of 50 points for completing the following:
TASK POINTS
Part A: Correct display of data 15
Part B: Correct code for calculation of monthly payments, total paid, and amount of remaining principal 25
Quality of code – 5 marks each for the submission 10
TOTAL 50
Breakdown for Quality of Code:
• Complete file header (see under the Submission heading for an example)
• Design (appropriate use and naming of variable
• Comments in the code
• Layout (indentation / spacing)
Submission
• Filename naming convention Assign1A_<UofA_ID_Number>.m
Ex. U of A ID Number: 1234567890 filename for assignment #1 is Assign1A_1234567890.m
• Submit only your .m file under Assignment 1 section in your eClass/Moodle account.
• A sample header is provided below, which must be included in all assignments:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Course: ENCMP 100
% Assignment: 1
% Lab Section: A2
% Name: Joe MacDonald % CCID: jmac
% U of A ID: 1234567890
%
% Acknowledgements:
% I received help from Jason Smith on matrix multiplication % % Description: % This program will show some basic matrix manipulations.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NOTE: When including the header from above, please change the details to contain your information. Also this header information must be included in all assignment, failure to do so will result in a failing assignment mark.
Background
The simplest way to define a matrix is to use a list of numbers. For example, the statement x = [1 2 3 4] will return the row vector:
x =
1 2 3 4
A new row is indicated by a semicolon. An example of a matrix containing both rows and columns is created with the statement y = [1 2 3 4; 2 3 4 5; 3 4 5 6], which returns:
y =
1 2 3 4
2 3 4 5
3 4 5 6
The colon operator is very powerful for defining new matrices and modifying existing ones. When a colon is used in a matrix reference in place of a specific index number, the colon represents the entire row or column. For example, the statement a = y(:,1) will equate matrix a to column 1 of matrix y.
MATLAB contains many built-in functions to create and manipulate/analyze matrices. These include sum, max, min, mean, median, and mode, as well as many matrix algebra functions.
MATLAB supports two types of operations between arrays, known as array operations and matrix operations.
Array operations are operations that are performed between arrays on an element-byelement basis. For example, if
.
Note: The number of rows and columns in both arrays must be the same.
, then .
Matrix operations, in contrast, follow the normal rules of linear algebra, such as matrix multiplication. In linear algebra, the product is defined by the equation
then a * b 115 135 and is represented
in MATLAB by the expression A*B. Recall that matrix multiplication is not commutative
– the order in which matrices are multiplied is important. For example, the result of B*A is .
Note: The number of columns in matrix a must be equal to the number of rows in matrix b.
Important: MATLAB uses a special symbol to distinguish array operations from matrix operations. A period is used before the symbol to indicate an array operation. For example,
• The MATLAB form for array multiplication is A .* B
• The MATLAB form for matrix multiplication is A * B
Assignment Description:
Part A: Basic Operations with Matrices
In this portion of the assignment you will be asked to create two arrays, perform some manipulations on the arrays and print the results to the screen.
Important: For the testing of this portion of the assignment, the automatic echoing of values in the command window must be suppressed. Please ensure you put a semicolon (;) at the end of each statement in order to suppress the echoing of values.
The program must perform the following steps:
1. Populate an array A. Display the array A contents to the command window with the title “Matrix A:”. The array A should represent the following:
2. Populate an array B. Display the array B contents to the command window with the title “Matrix B:”. The array B should represent the following:
3. Select row 2 in matrix A using the colon operator. Display the output to the command window with the title “Row 2 in matrix A:”.
4. Select column 1 in matrix B using the colon operator. Display the output to the command window with the title “Column 1 in matrix B:”.
5. Use the built-in sum command to find the sum of each column in matrix A. Display the results to the command window with the title “Sum of matrix
A:”.
6. Add the matrices A and B. Display the results to the command window with the title “Adding matrices A and B:”.
7. Find the array (element-by-element) multiplication of A and B. Display the results to the command window with the title “Array multiplication of A and B:”.
8. Find the matrix multiplication of A and B. Display the results to the command window with the title “Matrix multiplication of A and B:”.
9. Find the matrix multiplication of B and A. Display the results to the command window with the title “Matrix multiplication of B and A:”.
Your results must match exactly with the screenshot below:
Part A Submission:
For part A of this assignment, please submit your solution to eClass under Assignment 1. With the following naming convention:
Assign1A_<UofA_ID>.m
Ex. U of A ID Number: 1234567890 filename will be
Assign1A_1234567890.m
Part B: Mortgage Calculator
In this portion of the assignment, you are required to develop an m-file that calculates mortgage payments based on compound interest formulas.
The m-file should prompt a user to input the amount borrowed (principal), , the number of monthly payments, , and an annual interest rate in percent.
The program should convert the annual interest rate into a monthly interest rate
. The division includes the number of months in a year and a factor of 100
which takes care of the conversion between % and decimal.
Next the program should calculate monthly payments given as:
The total paid (calculated by multiplying the monthly payment by the number of monthly payments)
The amount of principal remaining after 12 months, , calculated as:
Your program should print the results of these computations to the command window with text explaining each value.
Run your code assuming that you want to buy a $400,000 home and a 30-year mortgage at a fixed annual interest rate of 5%. Your results should match exactly like this:
Hints:
1. A power operation in MATLAB is accomplished by the ^ operator. For example 23 is written 2^3 in MATLAB.
2. Type help input to learn about how to use the command input to prompt users for input and to record their entries from the command window.
Part B Submission:
For part B of this assignment, please submit your solution to eClass under Assignment 1B. With the following naming convention:
Assign1B_<UofA_ID>.m
Ex. U of A ID Number: 1234567890 filename will be
Assign1B_1234567890.m




Reviews
There are no reviews yet.