Question: In this problem you will create your own function to perform matrix operations using loops and scalar multiplication, scalar addition, and scalar subtraction. The purpose

In this problem you will create your own function to perform matrix operations using loops and
scalar multiplication, scalar addition, and scalar subtraction. The purpose of this assignment is (1)
to provide experience using loops with arrays and (2) to provide experience with matrix algebra.
MATLAB does have built-in matrix functions such as the inverse function (inv), the transpose
function (transpose or "'"), the determinant function (det), matrix addition (+), matrix
subtraction (-), and matrix multiplication (*). Your code may not use MATLAB's built-in matrix
functions. Similarly, your code may not use MATLAB's vectorization syntax (i.e., the dot operators)
such "./" and ".*". All computations must be performed using loops that process individual
array elements one at a time. Code that uses the built-in MATLAB matrix functions or
vectorization will receive no credit.
Create a function called MatrixOps that computes various matrix operations:
function [status, result]= MatrixOps (op, a1, a2)
% your code here
end
where the variables are defined as follows:
op a number indicating the desired matrix operation
a1
a matrix of numbers
a2 a matrix of numbers
status indicates if the calculation was successful (value =0 or 1)
result an array containing the result of the calculation or 0
if the calculation was unsuccessful
The table below shows the calculation to perform for each value of op :
For op=4,5, or 6, the value a 2 is not used. For these three cases, your code should ignore the value
but a value must still be passed to the function when it is called. An easy way to handle this is to
simply pass an empty array to your code when you call it as in this example:
[s,r]=MatrixOps(5,[12;34],[]);
Your code should set the value of status to 1 to indicate that the calculation was successful, and 0
to indicate that it was not. The calculation is unsuccessful if the dimensions of a 1 and a 2 are
incompatible with each other or if the value of op is not one of the defined values. For op=4, your
code should be restricted to handling only square matrices that are 33 or smaller. If the dimension
is larger than 33, or the matrix is not square, your code should indicate that the calculation was
unsuccessful. Likewise, for op=6, your code should be restricted to handling only square matrices
that are 22 or smaller. If the dimension is larger than 22, or the matrix is not square, your code
should indicate that the calculation was unsuccessful. If the calculation is unsuccessful, your code
should set result to 0. Otherwise, the value of result should be the result of the matrix
calculation.
 In this problem you will create your own function to perform

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!