Question

Problem1: (5 Points) Write a function with the header: function [A_Transp, errFlag] myMatrixChecker (A) that transposes a square matrix A. If A is not square, myMatrixChecker should return -1 for errFlag and A_Transp should be a matrix of zeros of the same size as A. The function should also write a message to the screen telling the user that the matrix is not square. If A is square, errFlag should be 0 and A_Transp should be the transpose of A. No message is reported.

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

Open MATLab ---> In Home tab ----> Click on New -----> Select function

paste the following code and save it by it's default name.

function [A_Transp,errFlag] = myMatrixChecker(A)
%Summary of this function goes here
% Detailed explanation goes here
B=size(A);%to find size
if B(1)==B(2)% to find whether it is square matrix or not
A_Transp = A'% for transpose
errFlag = 0
else
A_Trans=zeros(B)%to produce zeros matrix of input matrix size
errFlag = -1
disp('Given Matrix is not a Square Matrix')
end

end

---> In Home tab ----> Click on New -----> Select Script

paste the following code, save it and run it by keeping both function file and script file in same folder.

clear all
A = input('Enter input Matrix of any size:');%Asks for user input
myMatrixChecker(A);% calls function

Add a comment
Know the answer?
Add Answer to:
Problem1: (5 Points) Write a function with the header: function [A_Transp, errFlag] myMatrixChecker (A) that transposes...
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
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