Question

In: Mechanical Engineering

use matlab to create a function that finds inverse of 2x2 matrix and returns result. Should...

use matlab to create a function that finds inverse of 2x2 matrix and returns result. Should be a error check to make sure matrix is 2x2, and nonsingular.

Solutions

Expert Solution

Matlab code:

______________________________________________________________________________

a = [4 7; 2 6];
det_a = (a(1,1)*a(2,2) - a(1,2)*a(2,1));
s = size(a);
if det_a == 0 || s(1,1) ~= 2 || s(1,2) ~= 2
fprintf('Determinant of the provided matrix is zero or either size of the matrix is not 2x2 hence inverse not possible')
else
a1 = [a(2,2) -a(1,2) ; -a(2,1) a(1,1)];
inv_a = (1/det_a)*a1
end

____________________________________________________________________________

Above code will use the direct method of finding inverse of an 2x2 matrix. If the matrix size is different than 2x2 or it is singular code will give an message that provided matrix is not correct.

Please provide the feedback.


Related Solutions

IN MATLAB, Create a 8x8 magic matrix. Then use MATLAB built in function, sum, to calculate...
IN MATLAB, Create a 8x8 magic matrix. Then use MATLAB built in function, sum, to calculate the sum of each column. Use subscript notation to find the 6th element and the last element of each magic square. Find the maximum of all the elements in each magic square.
MATLAB: Attempting to use the inverse mapping approach and take a 3x3 matrix that will rotate...
MATLAB: Attempting to use the inverse mapping approach and take a 3x3 matrix that will rotate an image. The image is 540 x 420. attempting to write DOUBLE FOR LOOPS that will step through each and every pixel location. I cannot use any Toolbox Functions. Please write a double for loop that will allow this to happen! [xold,yold,k] = size(A); Rotation = [cosd(angle) -sind(angle) 0 ; sin(angle) cos(angle) 0; 0 0 1]; InverseRotation = double(inv(Rotation));
Using a system of equations, prove that a 2x2 matrix A has a right inverse if...
Using a system of equations, prove that a 2x2 matrix A has a right inverse if and only if it has a left inverse.
Matlab You will write a function to calculate the determinant of a matrix. It should work...
Matlab You will write a function to calculate the determinant of a matrix. It should work for any size matrix. Remember that the determinant can be calculated by multiplying the diagonal elements of an upper right triangular matrix. Your function will take a matrix passed to it and put it in upper right triangular form. You will work down the diagonal beginning at row 1 column 1, then row 2 column 2, etc. Note that the row and column numbers...
11.1      Determine the matrix inverse for the following system: 10x1 + 2x2 − x3 = −27...
11.1      Determine the matrix inverse for the following system: 10x1 + 2x2 − x3 = −27 −3x1 −6x2 +2x3 = −61.5 x1   + x2   +5x3 = −21.5 Check your results by verifying that [A][A]-1 = [I ]. Do not use a pivoting strategy. Calculate A^-1 using the LU decomposition of A. Use the Matlab lu command to perform the LU decomposition. Use the Matlab backslash \ operator to perform intermediate linear system solutions. Use Matlab matrix multiplication to verify that...
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.
Use this theorem to find the inverse of the given matrix or show that no inverse...
Use this theorem to find the inverse of the given matrix or show that no inverse exists. (If an answer does not exist, enter DNE in any cell.) 1    2    5    1 −1    0    2    1 2    1    −5    0 1    1    2    1
Write a GLM function named getInverse that returns the inverse of A. If A does not...
Write a GLM function named getInverse that returns the inverse of A. If A does not have an inverse, the function returns the identify matrix. Assume A is 3x3.
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.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT