Question

Question 1 a. Define the following matrices in a script file (M-file), ? = ( 8...

Question 1

a. Define the following matrices in a script file (M-file), ? = ( 8 9 10 11; 23 9 16 15 ;11 12 3 6; 1 2 8 9 ) ? = ( 2 21 7 15; 12 4 8 22; 23 9 5 13; 23 4 21 22) ℎ = (4 9 12 15)

b. Add suitable lines of codes to the M-file to do the following. Each of the following points should be coded in only one statement.

i. Compute the array product (element by element product) of f and g.

ii. Compute the matrix product of f and the transpose of h.

iii. Invert matrices f and g using the “inv” command.

iv. Extract all first and third row elements of matrix f in a newly defined array j.

v. Extract all the elements of the second column of matrix f in a newly defined array k.

vi. Store the sum of each row and column of matrix f using the “sum” command in a newly defined array m (of size 24). The first row elements of m should equal the sum of the columns, and the second row elements equal the sum of the rows.

vii. Delete the 1st and 3rd rows of matrix g.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

clc
clear
f = [8 9 10 11; 23 9 16 15 ;11 12 3 6; 1 2 8 9];
g = [2 21 7 15; 12 4 8 22; 23 9 5 13; 23 4 21 22];
h = [4 9 12 15];

disp("Element wise product of f and g =");
disp(f.*g);

disp("Matrix product of f and the transpose of h = ");
disp(f*h');

disp("Inverse of matrix f = ");
disp(inv(f));
disp("Inverse of matrix g = ");
disp(inv(g));

j = [f(1,:);f(3,:)];
disp("Matrix j = ");
disp(j);

k = f(:, 2);
disp("Matrix k = ");
disp(k);

m =[sum(f(:, 1)) sum(f(:, 2)) sum(f(:, 3)) sum(f(:, 4));sum(f(1,:)) sum(f(2,:)) sum(f(3,:)) sum(f(4,:))];
disp("Matrix m = ");
disp(m);

disp("Matrix g on removing 1 and 3 row = ");
g([1,3],:) = [];
disp(g);

Output:

Add a comment
Know the answer?
Add Answer to:
Question 1 a. Define the following matrices in a script file (M-file), ? = ( 8...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • cope the code please thanks Write a MATLAB code to obtain the following. Keep your code...

    cope the code please thanks Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your source code and command widow outcomes and screen shots of any plots in your solution. Generate a matrix "A" as follow. A= 16 6 8 2 10 18 12 14 4 I. II. Divide the matrix A by 2 and store the result in a matrix B. Combine matrices A & B to obtain the following matrix C. Also...

  • Write a program that reads a matrix from the keyboard and displays the summations of all...

    Write a program that reads a matrix from the keyboard and displays the summations of all its rows on the screen. The size of matrix (i.e. the number of rows and columns) as well as its elements are read from the keyboard. A sample execution of this program is illustrated below: Enter the number of rows of the matrix: 3 Enter the number of columns of the matrix: 4 Enter the element at row 1 and chd umn 1: 1...

  • Question A matrix of dimensions m × n (an m-by-n matrix) is an ordered collection of m × n elemen...

    Question A matrix of dimensions m × n (an m-by-n matrix) is an ordered collection of m × n elements. which are called eernents (or components). The elements of an (m × n)-dimensional matrix A are denoted as a,, where 1im and1 S, symbolically, written as, A-a(1,1) S (i.j) S(m, ). Written in the familiar notation: 01,1 am Gm,n A3×3matrix The horizontal and vertical lines of entries in a matrix are called rows and columns, respectively A matrix with the...

  • Problem 1 Write your code in the file MatrixOps.java. . Consider the following definitions from matrix...

    Problem 1 Write your code in the file MatrixOps.java. . Consider the following definitions from matrix algebra: A vector is a one-dimensional set of numbers, such as [42 9 20]. The dot product of two equal-length vectors A and B is computed by multiplying the first entry of A by the first entry of B, the second entry of A by the second entry of B, etc., and then summing these products. For example, the dot product of [42 9...

  • on matlab (1) Matrices are entered row-wise. Row commas. Enter 1 2 3 (2) Element A,...

    on matlab (1) Matrices are entered row-wise. Row commas. Enter 1 2 3 (2) Element A, of matrix A is accesser (3) Correcting an entry is easy to (4) Any submatrix of Ais obtained by d row wise. Rows are separated by semicolons and columns are separated by spaces ner A l 23:45 6. B and hit the return/enter kry matrix A is accessed as A Enter and hit the returnerter key an entry is easy through indesine Enter 19...

  • An m×n array A of real numbers is a Monge array if for all i,j,k, and l such that 1≤i<k≤m and ...

    An m×n array A of real numbers is a Monge array if for all i,j,k, and l such that 1≤i<k≤m and 1≤j<l≤n , we have >A[i,j]+a[k,l]≤A[i,l]+A[k,j]> In other words, whenever we pick two rows and two columns of a Monge array and consider the four elements at the intersections of the rows and columns, the sum of the upper-left and lower-right elements is less than or equal to the sum of the lower-left and upper-right elements. For example, the following...

  • Matlab answer only Form 1 6) [10 pts] Consider the following two matrices B=[S A 3...

    Matlab answer only Form 1 6) [10 pts] Consider the following two matrices B=[S A 3 1 5 -7 4 6-3] a) Obtain the sum of each row of matrix A. b) Use the size function to create a magic matrix P which has the same size as matrix A. c) Create a matrix called Q from the second column of matrix A d) Extract the four numbers in the lower left-hand corner of matrix A and create matrix R....

  • second picture is output of the mathlab code Important Note: For testing of this part of the assignment, the automatic printing of values in the com mand window must not be used. Please make sure...

    second picture is output of the mathlab code Important Note: For testing of this part of the assignment, the automatic printing of values in the com mand window must not be used. Please make sure you put semicolon ω at the end of each line. For this part your program should perform following tasks 1. Create a Matrix A. Show the contents of matrix A to command window with the title Matrix A:". The Matrix A should be defined as...

  • S.A vector IS givell by [5, 17,-3, 8, 0,-7, 12, 15, 20,-6, 6, 4,-7, 16]. Write...

    S.A vector IS givell by [5, 17,-3, 8, 0,-7, 12, 15, 20,-6, 6, 4,-7, 16]. Write a program as a 3 or 5, and, raises to the power of 3 the elements that are script tile that doubles the elements that are positive and are divisible by negative but greater than -5. following values. The value of each element in the first row is the number of the 6. Write a program in a script file that creates an matrix...

  • C++ Lab 11 – Is This Box a Magic Box? Objectives: Define a two dimensional array Understand h...

    C++ Lab 11 – Is This Box a Magic Box? Objectives: Define a two dimensional array Understand how to traverse a two dimensional array Code and run a program that processes a two dimensional array Instructions: A magic square is a matrix (two dimensional arrays) in which the sum of each row, sum of each column, sum of the main diagonal, and sum of the reverse diagonal are all the same value. You are to code a program to determine...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT