Question
Please help with this matlab questions 1. Write a function that has one input, a square (n x n, for any integer n) matrix. It
Please help with this matlab questions
1. Write a function that has one input, a square (n x n, for any integer n) matrix. It should return three outputs: D, A, and B. Every square matrix has a upper left to lower right diagonal. For instance, the following matrix: [ 1 2 3 4 5 6 7 8 9 ] Has the diagonal: [ 1 5 9 ] Your first output, D, should be the diagonal of your input matrix, with all other numbers set to 0. In the above matrix, it would be: [ 1 0 0 0 5 0 0 0 9 ] A and B should be the numbers ABOVE and BELOW that diagonal, respectively, with all other numbers set to 0. For instance, A in the above example would be: [ 0 2 3 0 0 6 0 0 0 ] And B would be: [ 0 0 0 4 0 0 7 8 0 ] We strongly recommend using nested loops to accomplish these tasks, though other answers will be accepted.
2. Please write a function with one input, a matrix, and one output, a matrix of the same size. The output matrix should be the input matrix mirrored on the vertical axis. For instance, the input: [ 1 2 3 4 5 6 7 8 9 ] Would become: [ 3 2 1 6 5 4 9 8 7 ] And the input: [ 1 1 2 2 2 1 1 1 2 2 1 2 ] Would become: [ 2 2 1 1 1 2 2 2 1 1 2 1 ] Note that this functions slightly differently for inputs with odd and even numbers of columns. For an odd number of columns, your centermost column stays the same. For an even number of columns, all columns are moved in the resulting output. You can use the function [yDim, xDim] = size(matrixName) To determine the number of rows (yDim) and columns (xDim) of any matrix (matrixName). This may help you in completing your task. We also strongly recommend the use of nested loops.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started