Question

9) [6 Pts) Write a code to transpose the elements of an input matrix. You may definen and use the function rand(n,n) to creat
0 0
Add a comment Improve this question Transcribed image text
Answer #1

MatLab program

clear
clc
n=3;
% creating original matrix
A=rand(n,n);
% creating matrix for transpose
At=zeros(n,n);
for i=1:n
    for j=1:n
        % interchanging rows and columns
        At(i,j)=A(j,i);
    end
end
fprintf('original matrix\n')
disp(A);
fprintf('\ntranspose matrix\n')
disp(At)

Screenshot:

1 clear 2 clc 3 n=3; 4% creating original matrix 5 A=rand (n,n); 6% creating matrix for transpose 7 At=zeros (n,n); 8 for i=1

Save the above program and execute it.

Result:

>> trp original matrix 0.9649 0.9572 0.1576 0.4854 0.9706 0.8003 0.1419 0.4218 0.9157 transpose matrix 0.9649 0.1576 0.9572 0

I hope this will help you.

Add a comment
Know the answer?
Add Answer to:
9) [6 Pts) Write a code to transpose the elements of an input matrix. You may...
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
  • Write a function Transpose that transposes a matrix T with M rows and N colums. The...

    Write a function Transpose that transposes a matrix T with M rows and N colums. The transposed matrix, TT, should have N rows and M columns. Example. Given the matrix T. (C++14) Example: 1 2 3 0 -6 7 The transposed matrix TT is 1 0 2 -6 3 7 DEFAULT CODE: Add to code as needed: #include <iostream> #include <string> #include <cmath> using namespace std; void Transpose(int T[100][100], int TT[100][100], int M, int N) { int i; int j;...

  • Bonus 1 • Write a java program to transpose a matrix mat[N][M], where: 1) You ask...

    Bonus 1 • Write a java program to transpose a matrix mat[N][M], where: 1) You ask the user to input N and M 2) You then ask the user to input the matrix row by row 3) You transpose the matrix 4) You output the transpose to the user

  • Create a function to transpose Array elements as follows: (Problem Set 11 #1) Transposed 10 X...

    Create a function to transpose Array elements as follows: (Problem Set 11 #1) Transposed 10 X 10 Array -- Sample Output NOTE: This NOT a matrix "transpose". (ie: rows to columns) This is simply moving elements of the array to the opposite order. Ex: (a[1][1] is moved to a[10][10] and a[1][2] is moved to a[9][10] etc. and finally a[10][10] is moved to a[1][1]) ORIGINAL TRANSPOSED 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5...

  • 1. For a matrix 5 9 6 (1) Use Matlab command to calculate the transpose matrix...

    1. For a matrix 5 9 6 (1) Use Matlab command to calculate the transpose matrix (2) Use Matlab to calculate the determinant of the matrix (3) Justify if the matrix has the inverse matrix and use Matlab to calculate the inverse Matrix (4) Use Matlab to calculate the eignvalues and eignvectors of the Matrix

  • Matlab code 4) Write a function leadzero(v) which takes as input a vector v and as...

    Matlab code 4) Write a function leadzero(v) which takes as input a vector v and as output, c, returns the number of zeros at the beginning of v (number of zero elements before any non-zero element). For example, for input (-5, 5, 11] the output would be 0. If the input is [0, 0, 3, 0, 0, 0], the output would be 2. If the input is [0, 0, 0, 0, 7, 4) the output would be 4. 5) Write...

  • Please use C !!! Write a C function matrixTranspose that takes a two-dimensional array as its...

    Please use C !!! Write a C function matrixTranspose that takes a two-dimensional array as its input argument then transposes its elements and prints the results. Develop the matrixTranspose method with two different methods: 1. Assume the matrix is a square matrix. This will make finding the transpose a simple swapping of the arrays’ elements and it can be done in place. 2. Generalize your function to work with any NxM matrix where N≠M. You will need to properly handle...

  • Stdio.h format. Proper commenting please. Needs to be able to be saved as a .C file....

    Stdio.h format. Proper commenting please. Needs to be able to be saved as a .C file. Thanks in advance. Please do not copy and paste any of the other answers already on this site as they do not work. If you can't do it please don't answer my question. 1) A matrix M with i rows, j columns can be transposed into a matrix N having j rows and i columns by simply setting the value of Nob equal to...

  • *** Write a function called reverse_diag that creates a square matrix whose elements are 0 except...

    *** Write a function called reverse_diag that creates a square matrix whose elements are 0 except for 1s on the reverse diagonal from top right to bottom left. The reverse diagonal of an nby- n matrix consists of the elements at the following indexes: (1, n), (2, n-1), (3, n-2), … (n, 1). The function takes one positive integer input argument named n, which is the size of the matrix, and returns the matrix itself as an output argument. Note...

  • LAB 1 2 5 7 6 9 3 8 . Write code to implement an adjacency matrix (2d matrix) which represents th...

    JAVA LAB 1 2 5 7 6 9 3 8 . Write code to implement an adjacency matrix (2d matrix) which represents the graph. Your code should contain a function called addEdgelint i, int j). Use this function to add the appropriate edges in your matrix. Write code to implement Depth-First-Search (DFS) and Breadth-First-Search (BFS) of your graph. Let 0 be the source Node . Traverse the graph using DFS, print the Nodes as they are visited. . Traverse the...

  • The assignment In this assignment you will take the Matrix addition and subtraction code and modify...

    The assignment In this assignment you will take the Matrix addition and subtraction code and modify it to utilize the following 1. Looping user input with menus in an AskUserinput function a. User decides which operation to use (add, subtract) on MatrixA and MatrixB b. User decides what scalar to multiply MatrixC by c. User can complete more than one operation or cancel. Please select the matrix operation 1- Matrix Addition A+ B 2-Matrix Subtraction A-B 3Scalar Multiplication sC 4-Cancel...

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