For this weeks assignment youll be making a function that ca

For this week’s assignment, you’ll be making a function that can not only add two matrices, but also multiply them, as well as a single matrix and a scalar.

Your function will need to correctly perform operations on the provided matrices and print out the resulting matrices.

Matrix A:

2

0

4

2

Matrix B:

1

3

2

0

Matrix C:

1

0

0

1

FOR YOUR ASSIGNMENT: You’ll be multiplying the provided matrices as follows:

(1) Matrix A * Matrix B

(2) Matrix B * Matrix A

(3) Matrix C * Matrix B

(4) Matrix A + Matrix B

(5) -4 * Matrix B

2

0

4

2

Solution

I am giving here three .m files save them with given name and run. You will get desired output.

add.m

function [ Y ] = add( A,B )
Y=A+B
end

mul.m

function [ Y ] = mul( A,B )
Y=A*B
end

main.m

clc;
close all;
clear all;
A=[2 0;4 2]
B=[1 3;2 0]
C=[1 0;0 1]
mul(A,B);
mul(B,A);
mul(C,B);
add(A,B);
mul(-4,B);

Output:-

A =

     2     0
     4     2


B =

     1     3
     2     0


C =

     1     0
     0     1


Y =

     2     6
     8    12


Y =

    14     6
     4     0


Y =

     1     3
     2     0


Y =

     3     3
     6     2


Y =

    -4   -12
    -8     0

For this week’s assignment, you’ll be making a function that can not only add two matrices, but also multiply them, as well as a single matrix and a scalar. You
For this week’s assignment, you’ll be making a function that can not only add two matrices, but also multiply them, as well as a single matrix and a scalar. You
For this week’s assignment, you’ll be making a function that can not only add two matrices, but also multiply them, as well as a single matrix and a scalar. You

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site