Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

With the use of M atlab , solve the following exercises and comment on each of t

ID: 3878918 • Letter: W

Question

With the use of Matlab, solve the following exercises and comment on each of them to see which process was carried out.

Using Matlab

1. In a single instruction, change all values from the diagonal of a square matrix to zero.

2. In a single instruction, substitute all the values of the diagonal of a square matrix for the elements of a given vector.

3. Sort the elements of a matrix from minor to major maintaining its shape (indication: use the reshape command.)

4. In a single instruction, reset all negative elements of a matrix.

5. In a single instruction, reset all the elements of a matrix that are between -1 and 1. (The logical conjunction is &).

6. Find out the number of elements in a matrix, so that in the end we have a number.

Explanation / Answer

Hi,

Ans 1-M=[1,2,3;4,5,6;7,8,9]
out = M - diag(diag(M));

Ans 2-
A = magic(4)
A = magic(4)
A =

16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
A(logical(eye(size(A)))) = [1,1,1,1]

Ans 3-
B = sort(A,2,'descend')

Ans 4
P=[-1,-2,3,4;-9,-3,2,6]
P(P<0)=1
P =

-1 -2 3 4
-9 -3 2 6

P =

1 1 3 4
1 1 2 6

Ans 5-
octave:14> N
N =

-0.20000 -0.30000 1.00000 5.00000
0.20000 0.50000 0.70000 9.00000

octave:15> N(N>=-1 & N<=1)
ans =

-0.20000
0.20000
-0.30000
0.50000
1.00000
0.70000

Ans 6-
octave:22> numel(N)
ans = 8

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote