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

Task 1: Working with Arrays in MatLab (5 pts) Create a MatLab script called a2ta

ID: 3790374 • Letter: T

Question

Task 1: Working with Arrays in MatLab (5 pts) Create a MatLab script called a2task1.m that computes the following tasks. The answers will appear in the Workspace. To view the larger structures, e.g., matrix A in Part 1, double click on the variable name in the Workspace and it will open up a window in your editor displaying it. 1. Create a matrix using the following line of code: A=gallery('gcdmat',7);. 2. Use array subscripting to assign the 6th column of A to a new vector named vec. 3. Assign the maximum value in vec to a new variable named v_max and the minimum value in vec to a new variable named v_min. 4. Use the repmat command to create a new 2x7 matrix called M such that each row of M is the transpose of vec. 5. Assign the diagonal elements of matrix A to a 7-element column vector named diagM. (Hint: there is a MatLab command that will help you with this). 6. Create a row vector samples1 that contains exactly 9 equally-spaced points ranging from 0 to 10. 7. Create a row vector samples2 that contains points spaced exactly 0.2 units apart over the range of 0 to 1.95, incrementing from 0.

Task 1: Working with Arrays in MatLab (5 pts) Create a MatLab script called a2taski.m that computes the following tasks. The answers will appear in the Workspace. To view the larger structures, e.g., matrix A in Part 1 double click on the variable name in the Workspace and it will open up a window in your editor displaying it. l. Create a matrix using the following line of code: A-gallerycgcdmat',7), 2. Use array subscripting to assign the 6th column of A to anew vector named vec. 3. Assign the maximum value in vec to a new variable named v max and the minimum value in vec to a new variable named v min. 4. Use the repmat command to create a new 2x7 matrix called M such that each row of M is the transpose of vec 5. Assign the diagonal elements of matrix A to a 7-element column vector named diagM (Hint: there is a MatLab command that will help you with this). 6. Create a row vector samplesi that contains exactly 9 equally-spaced points ranging from 0 to 10. 7. Create a row vector samples2 that contains points spaced exactly 0.2 units apart over the range of 0 to 1.95, incrementing from 0.

Explanation / Answer

Output of each of the commands is given below:

1.

A=gallery('gcdmat',7);
A;
A =

1 1 1 1 1 1 1
1 2 1 2 1 2 1
1 1 3 1 1 3 1
1 2 1 4 1 2 1
1 1 1 1 5 1 1
1 2 3 2 1 6 1
1 1 1 1 1 1 7

2.

vec=A(:,6)
vec =

1
2
3
2
1
6
1

3.

v_max=max(vec);

v_max=6

v_min=min(vec)
v_min = 1

4.

M=repmat(vec',2,1)
M =

1 2 3 2 1 6 1
1 2 3 2 1 6 1

5.

diagM=diag(A)
diagM =

1
2
3
4
5
6
7

6.

samples1=linspace(0,10,9)
samples1 =

Columns 1 through 7:

0.00000 1.25000 2.50000 3.75000 5.00000 6.25000 7.50000

Columns 8 and 9:

8.75000 10.00000

7.

startValue = 0;
endValue = 1.95;
stepSize=0.2;
samples2 = startValue:stepSize:endValue
samples2 =

Columns 1 through 7:

0.00000 0.20000 0.40000 0.60000 0.80000 1.00000 1.20000

Columns 8 through 10:

1.40000 1.60000 1.80000

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