Question

In: Computer Science

A. Write a function in MATLAB called findTranspose that takes in as input any matrix or...

A. Write a function in MATLAB called findTranspose that takes in as input any matrix or any vector and simply returns back the transpose of that input. You can always verify your answer by using the inbuilt transpose function in MATLAB, however, you cannot use the transpose function directly when writing your code. Here is the starter code that we are providing to help you get started

%x is the input vector or matrix. You can find the

%size that is the number of rows and the number

%of columns of x by using the size function in MATLAB function transpose_ret = findTranspose(x)

. . .

%transpose_ret is the variable that will contain the transpose of the input x end

Solutions

Expert Solution

Matlab function can be defined with the help of number of rows and number of columns which is given as input to justify the size of the matrix and also input of the matrix x.This can be done by giving input of any matrix or any vector.

MATLAB code snippet

r = input('Enter the no. of rows');

c = input('Enter no. of columns');

function transpose_ret = findTranspose(x)

[r c] = size(x);

transpose_ret = zeros(c,r);

for i = 1:r

for j = 1: c

transpose_ret(j,i) = x(i,j)

end

end

end

x = [1 3;2 5]; %x is given as input 2x2 matrix

transpose_ret = findTranspose(x); % transpose the matrix x

transpose_ret

OUTPUT 
Enter the no. of rows> 2
Enter no. of columns> 2
transpose_ret =

   1   0
   0   0

transpose_ret =

   1   0
   3   0

transpose_ret =

   1   2
   3   0

transpose_ret =

   1   2
   3   5

transpose_ret =

   1   2
   3   5

This can also be verified by using the transpose function

x = [1 3;2 5]; %x is given as input 2x2 matrix
transpose(x)

OUTPUT

ans =

   1   2
   3   5

Related Solutions

B. Write a function in MATLAB called findInverseOf2x2Matrix that takes in as input any square matrix...
B. Write a function in MATLAB called findInverseOf2x2Matrix that takes in as input any square matrix of size 2 × 2 and returns back the inverse of that matrix if one exists. If no inverse exists, print back a suitable error message. You can safely assume that we will test your code on square matrices of size 2 × 2 only. You can always verify your answer by using the inbuilt inverse function in MATLAB, however, you cannot use the...
Write a Matlab function for a matrix that takes in a matrix in echelon form and...
Write a Matlab function for a matrix that takes in a matrix in echelon form and will return the row canonical form. The function cannot use rref, or any other matlab built in functions.
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal...
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal matrix given as two vectors: n×1 vector v representing the main diagonal and (n−1)×1 vector w representing the upper diagonal. Have this function output the Cholesky factor of the matrix as a vector for the main diagonal and a vector for the upper diagonal and output the number of flops and, separately, the number of square roots used as well. Use only basic programming....
MATLAB Function: (Backward substitution) Write a function that takes an upper triangular matrix U, and a...
MATLAB Function: (Backward substitution) Write a function that takes an upper triangular matrix U, and a vector b as input and returns the solution of the linear system U x = b. Use this function in the case when U is made of the numbers [(3,2,1),(0,5,4),(0,0,6)], and b = [1,1,−6]^T.
Matlab Create/write a function that takes an input of x and y data, and a string...
Matlab Create/write a function that takes an input of x and y data, and a string (either linear? or quadratic), sets up a linear system of equations (Ax = b), and solves and plots the model.
Using Matlab, write a function that takes numeric data as its input argument and prints a...
Using Matlab, write a function that takes numeric data as its input argument and prints a message to the Command Window stating if the number is positive, or negative, or 0. This function should transfer an output value to the Workspace ONLY when the input value is negative. Please include a copiable code and the associated screenshots.
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a weighted sum of that numbers digits. The last digit of the number (the ones digit) has a weight of 1, so should be added to the sum "as is". The second from last digit (the tens digit) has a weight of 2, and so should be multiplied by 2 then added to the sum. The third from last digit should be multiplied by 1...
#Write a function called get_integer that takes as input one #variable, my_var. If my_var can be...
#Write a function called get_integer that takes as input one #variable, my_var. If my_var can be converted to an integer, #do so and return that integer. If my_var cannot be converted #to an integer, return a message that says, "Cannot convert!" # #For example, for "5" as the value of my_var, get_integer would #return the integer 5. If the value of my_var is the string #"Boggle.", then get_integer would return a string with the #value "Cannot convert!" # #Do not...
Write a recursive function (using Matlab) moreFactors(a,b,fact) that does the following: 1. Takes as an input...
Write a recursive function (using Matlab) moreFactors(a,b,fact) that does the following: 1. Takes as an input 3 positive integers. 2. Of the two integers a and b, the function returns the integer that has the most factors fact. 3. If both integers a and b have the same amount of factors fact, the function will return the larger integer. Test your function with the following: >> result=moreFactors(24,32,3) result = 24 (24 = 3^1 · 2^3 , 32 = 2^5 )...
Write a function called alternate that takes two positive integers, n and m, as input arguments...
Write a function called alternate that takes two positive integers, n and m, as input arguments (the function does not have to check the format of the input) and returns one matrix as an output argument. Each element of the n-by-m output matrix for which the sum of its indices is even is 1. All other elements are zero. For example, here is an example run: >> alternate(4,5) ans = 1 0 1 0 1 0 1 0 1 0...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT