MA1MSP留学生辅导、讲解Statistical Programming、C++编程辅导、讲解c++ 辅导Python编程|辅导R语言程序
- 首页 >> 其他 MA1MSP: Mathematical and Statistical Programming
Assignment 3
This assignment counts to 10% of the total marks of this module. Full marks of this
assignment can be gained from complete answers to ALL questions and emailing the
MATLAB script and function files to me at john.evans.18@nuist.edu.cn before 12pm
(noon) 16th May, 2019 (Thursday).
Note:
For this question you should submit two MATLAB files, with the file names MSP Asgn3a StudentID.m
for part (a) and MSP Asgn3b StudentID.m for part (b), where ’StudentID’ is your Student ID
number. Both files should be submitted together in the same email.
Please include your student ID in the subject line of the email.
At the beginning of the function or script, add a comment line to state ‘This is the function/
script for Part (x) of Assignment 3’ where ‘x’ is ‘a’ or ‘b’.
If either of the two files are missing or do not run then a mark of zero will be recorded for that
part of the question.
Marks will be deducted if students output to the command window anything that is not asked
for.
By submitting your work you are confirming that the code is your own, independent work.
(a) Write a function MSP Asgn3a StudentID, where ‘StudentID’ is your Student ID number. As
input, the function takes a matrix A and a scalar m. The function should take the following
actions:
If the matrix A is not square, return the error ‘Invalid input: the matrix must be square!’.
Otherwise, if the input scalar m equals to
1, return the determinant of A;
2, return the trace of A;
3, return the eigenvalues of A;
4, if A is invertible (e. g., the absolute value of the determinant of A is not less than 10?6
),
return the inverse of A. Otherwise, return the message ‘The matrix is non-invertible’;
none of the above, return the error ‘Invalid input for matrix operation’.
Except for the required output and error messages, the function should not write any extra
information to the command window.
[5 marks]
(b) Write a script MSP Asgn3b StudentID that performs the following steps:
(i) Define a 2 × 2 matrix B whose elements are 1, 2 and the last two digits of your student
number. So, if your student number ends in the digits 34, you should define
1(ii) By calling the function from part (a),
1. consider the following matrix,
C = 7B ? 5I
where I is the 2 × 2 identity matrix. Calculate the variables x, y, where x is the
determinant of C and y is the trace of C. Display in the command window a vector
with entries equal to x and y;
2. calculate the inverse matrix of C2 and display the output in the command window.
[Note: if the function from part (a) returns an error message that the input matrix
is not invertible, change one of the elements in B by either adding or subtracting 1
and run the script again. Submit the script with the updated B and add a comment
explaining how the elements in B differ from the last four digits in your student ID
number, and why.]
(iii) Define a 2 × 4 matrix D whose elements are the last five digits of your student number.
So, if your student number ends in the digits 68310001, you should define
By calling the function from part (a), write the eigenvalues of B1D (OR an automatically
generated error message) to the command window.
[5 marks]
2
Assignment 3
This assignment counts to 10% of the total marks of this module. Full marks of this
assignment can be gained from complete answers to ALL questions and emailing the
MATLAB script and function files to me at john.evans.18@nuist.edu.cn before 12pm
(noon) 16th May, 2019 (Thursday).
Note:
For this question you should submit two MATLAB files, with the file names MSP Asgn3a StudentID.m
for part (a) and MSP Asgn3b StudentID.m for part (b), where ’StudentID’ is your Student ID
number. Both files should be submitted together in the same email.
Please include your student ID in the subject line of the email.
At the beginning of the function or script, add a comment line to state ‘This is the function/
script for Part (x) of Assignment 3’ where ‘x’ is ‘a’ or ‘b’.
If either of the two files are missing or do not run then a mark of zero will be recorded for that
part of the question.
Marks will be deducted if students output to the command window anything that is not asked
for.
By submitting your work you are confirming that the code is your own, independent work.
(a) Write a function MSP Asgn3a StudentID, where ‘StudentID’ is your Student ID number. As
input, the function takes a matrix A and a scalar m. The function should take the following
actions:
If the matrix A is not square, return the error ‘Invalid input: the matrix must be square!’.
Otherwise, if the input scalar m equals to
1, return the determinant of A;
2, return the trace of A;
3, return the eigenvalues of A;
4, if A is invertible (e. g., the absolute value of the determinant of A is not less than 10?6
),
return the inverse of A. Otherwise, return the message ‘The matrix is non-invertible’;
none of the above, return the error ‘Invalid input for matrix operation’.
Except for the required output and error messages, the function should not write any extra
information to the command window.
[5 marks]
(b) Write a script MSP Asgn3b StudentID that performs the following steps:
(i) Define a 2 × 2 matrix B whose elements are 1, 2 and the last two digits of your student
number. So, if your student number ends in the digits 34, you should define
1(ii) By calling the function from part (a),
1. consider the following matrix,
C = 7B ? 5I
where I is the 2 × 2 identity matrix. Calculate the variables x, y, where x is the
determinant of C and y is the trace of C. Display in the command window a vector
with entries equal to x and y;
2. calculate the inverse matrix of C2 and display the output in the command window.
[Note: if the function from part (a) returns an error message that the input matrix
is not invertible, change one of the elements in B by either adding or subtracting 1
and run the script again. Submit the script with the updated B and add a comment
explaining how the elements in B differ from the last four digits in your student ID
number, and why.]
(iii) Define a 2 × 4 matrix D whose elements are the last five digits of your student number.
So, if your student number ends in the digits 68310001, you should define
By calling the function from part (a), write the eigenvalues of B1D (OR an automatically
generated error message) to the command window.
[5 marks]
2