Matrix Calculation Lec04: Matrix/Array Calculation/ Find index/Practice Trigonometric function X = 0.1:0.1:10; y=sin(x) X = 0.1:0.1:10; y=cos(x) X = 0.1:0.1:10; y=tan(x) x =0:0.1:10; Amp=2; Freq =1.2;...

1 answer below »
Please answer the inclass assignment question 1- 8 from reference lecture 2. Please remember the assignment need to be submitted in a .mlx file and pdf.


Matrix Calculation Lec04: Matrix/Array Calculation/ Find index/Practice Trigonometric function X = 0.1:0.1:10; y=sin(x) X = 0.1:0.1:10; y=cos(x) X = 0.1:0.1:10; y=tan(x) x =0:0.1:10; Amp=2; Freq =1.2; Phase =3; Bias =1.5; y=Amp*sin(Freq*x+Phase)+Bias; x is in radius Close-form function Free vibration m k x = x0.*cos(wn.*t)+(xd0/wn.*sin(wn.*t)); System of linear equations: w = 2a +2b -7c -2d x = 3a + 2b – 5c +6d y = 9a – 8b + c - 4d z = a +5b + 3c – d w=5, x= -17, y=14 and z=9 Find the value of a, b, c and d Find index under conditions Find index: Syntax DescriptionReturn value x = find(A)Find indices and values of nonzero elements, return linear index[1;2;4;6;7;8;9] x = find(A<5) find="" the="" elements="" that="" are="" less="" than="" 5,="" return="" linear="" index="" [1;2;3;4;5;7]="" [row="" col]=""><5) find="" the="" elements="" that="" are="" less="" than="" 5,="" return="" sub="" index="" row="[1;2;3;1;2;1]" col="[1;1;1;2;2;3];" x="max(A)" maximum="" elements="" of="" each="" column,="" return="" max="" elements="" x="min(A)" minimum="" elements="" of="" each="" column,="" return="" min="" elements="" x="max(A(:))" maximum="" elements="" of="" reshaped="" a(column="" only),="" return="" linear="" index="" 9="" a(a="">8)=0Replace all elements greater than 8 in A to be 0 A 6 In class practice: Assign results to variables namely problem1, problem2 … etc. (1) Generate matrix A . Find the linear index of largest element in matrix A. (2) Generate matrix B. Find the subscript index of smallest element in matrix B. (3) Generate a 4 by 3 matrix with all elements equal to 2. (5) Replace all elements greater than 3 in B to be 0. (4) Replace all elements in A to be 2. (6) Generate matrix C . Find the linear index of element equal to 0, and convert the linear index to subscript index. (7) Generate matrix D. Find the value of smallest element of D, and find the linear index of all these elements. (8) Calculate y=3*sin(x+2)+1, when x = [1,2…,10] 0246810 x -1 -0.5 0 0.5 1 y sin 0246810 x -1 -0.5 0 0.5 1 y cos 0246810 x -10 -5 0 5 10 y tan 051015 x -1 0 1 2 3 4 y Amp=2,Freq=1.2,Phase=3,Bias=1.5 00.511.52 time(s) -0.3 -0.2 -0.1 0 0.1 0.2 0.3 d i s p l a c e m e n t ( i n c h )
Answered Same DayApr 15, 2021

Answer To: Matrix Calculation Lec04: Matrix/Array Calculation/ Find index/Practice Trigonometric function X =...

J Anitha answered on Apr 16 2021
140 Votes
Ex1.mlx
[Content_Types].xml

_rels/.rels

matlab/document.xml
A = [1 2 3;4 5 6;7 8 9] %Matrix A
disp('Largest element in Matrix A')
t = max(A(:)) %Find largest element in the Matrix A
for i = 1 : 3
for j = 1 : 3
if((A(i,j))==t) %subscript index of the largest element
p = i
q = j
end
end
end
s = [3,3] % size of the Matrix
disp('Linear index of largest element')
ind = sub2ind(s,p,q) %linear index of the largest element
matlab/output.xml
manual code ready 0.4 matrix A 3×3 3 3 double 1 2 3
4 5 6
7 8 9
double double [[{"value":"{\"value\":\"1\"}"},{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"3\"}"}]] 1 text Largest element in Matrix A
false false 2 variable t 9 1 1 3 variable p 3 1 1 7 variable q 3 1 1 8 matrix s 1×2 1 2 double 3 3
double double [[{"value":"{\"value\":\"3\"}"},{"value":"{\"value\":\"3\"}"}]] 12 text Linear index of largest element
false false 13 variable ind 9 1 1 14 true false A = [1 2 3;4 5 6;7 8 9] %Matrix A 0 0 0 0 false false disp('Largest element in Matrix A') 1 1 1 1 false false t = max(A(:)) %Find largest element in the Matrix A 2 2 2 2 false false for i = 1 : 3
for j = 1 : 3
if((A(i,j))==t) %subscript index of the largest element
p = i
q = j
end
end
end 3 3 10 3 4 false false s = [3,3] 4 11 11 5 false false disp('Linear index of largest element') 5 12 12 6 false true ind = sub2ind(s,p,q) %linear index of the largest element
6 13 13 7
metadata/coreProperties.xml
2020-04-16T14:35:09Z 2020-04-16T15:16:34Z
metadata/mwcoreProperties.xml
application/vnd.mathworks.matlab.code MATLAB Code R2020a
metadata/mwcorePropertiesExtension.xml
9.8.0.1298242 449ecf2e-7271-4b38-91fe-1a0870236e69
metadata/mwcorePropertiesReleaseInfo.xml

9.8.0.1323502
R2020a

Feb 25 2020
3410093040
Ex1.pdf
A = [1 2 3;4 5 6;7 8 9] %Matrix A
A = 3×3
1 2 3
4 5 6
7 8 9
disp('Largest element in Matrix A')
Largest element in Matrix A
t = max(A(:)) %Find largest element in the Matrix A
t = 9
for i = 1 : 3
for j = 1 : 3
if((A(i,j))==t) %subscript index of the largest element
p = i
q = j
end
end
end
p = 3
q = 3
s = [3,3] % size of the Matrix
s = 1×2
3 3
disp('Linear index of largest element')
Linear index of largest element
ind = sub2ind(s,p,q) %linear index of the largest element
ind = 9
1
Ex2.mlx
[Content_Types].xml

_rels/.rels

matlab/document.xml
B = [6 2 1;4 2 7;8 3 5] %Matrix B
disp('Smallest element in Matrix B')
t = min(B(:)) %Find Smallest element in the Matrix B
disp('subscript index of smallest element in matrix B')
for i = 1 : 3
for j = 1 : 3
if((B(i,j))==t) %subscript index of the smallest element
p = i
q = j
end
end
end
matlab/output.xml
manual code ready 0.4 matrix B 3×3 3 3 double 6 2 1
4 2 7
8 3 5
double double [[{"value":"{\"value\":\"6\"}"},{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"1\"}"}]] 1 text Smallest element in Matrix B
false false 2 variable t 1 1 1 3 text subscript index of smallest element in matrix B
false false 4 variable p 1 1 1 8 variable q 3 1 1 9 true false B = [6 2 1;4 2 7;8 3 5] %Matrix B 0 0 0 0 false false disp('Smallest element in Matrix B') 1 1 1 1 false false t = min(B(:)) %Find Smallest element in the Matrix B 2 2 2 2 false false disp('subscript index of smallest element in matrix B') 3 3 3 3 false true for i = 1 : 3
for j = 1 : 3
if((B(i,j))==t) %subscript index of the smallest element
p = i
q = j
end
end
end 4 4 11 4 5
metadata/coreProperties.xml
2020-04-16T15:18:54Z 2020-04-16T15:29:01Z
metadata/mwcoreProperties.xml
application/vnd.mathworks.matlab.code MATLAB Code R2020a
metadata/mwcorePropertiesExtension.xml
9.8.0.1298242 08243660-a54e-4a6b-a35f-370dcf863db6
metadata/mwcorePropertiesReleaseInfo.xml

9.8.0.1323502
R2020a

Feb 25 2020
3410093040
Ex2.pdf
B = [6 2 1;4 2 7;8 3 5] %Matrix B
B = 3×3
6 2 1
4 2 7
8 3 5
disp('Smallest element in Matrix B')
Smallest element in Matrix B
t = min(B(:)) %Find Smallest element in the Matrix B
t = 1
disp('subscript index of smallest element in matrix B')
subscript index of smallest element in matrix B
for i = 1 : 3
for j = 1 : 3
if((B(i,j))==t) %subscript index of the smallest element
p = i
q = j
end
end
end
p = 1
q = 3
1
Ex3.mlx
[Content_Types].xml

_rels/.rels

matlab/document.xml
C = [2 2 2;2 2 2;2 2 2;2 2 2]
matlab/output.xml
manual code ready 0.4 matrix C 4×3 4 3 double 2 2 2
2 2 2
2 2 2
2 2 2
double double [[{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"}]] 1 true true C = [2 2 2;2 2 2;2 2 2;2 2 2] 0 0 0 0
metadata/coreProperties.xml
2020-04-16T15:31:45Z 2020-04-16T15:31:45Z
metadata/mwcoreProperties.xml
application/vnd.mathworks.matlab.code MATLAB Code R2020a
metadata/mwcorePropertiesExtension.xml
9.8.0.1298242 6ab6c339-5346-4886-8ea8-adf88caca200
metadata/mwcorePropertiesReleaseInfo.xml

9.8.0.1323502
R2020a

Feb 25 2020
3410093040
Ex3.pdf
C = [2 2 2;2 2 2;2 2 2;2 2 2]
C = 4×3
2 2 2
2 2 2
2 2 2
2 2 2
1
Ex4.mlx
[Content_Types].xml

_rels/.rels

matlab/document.xml
A = [1 2 3;4 5 6;7 8 9]
A(1,1)=2 %Replace all elements in A to 2
A(1,2)=2
A(1,3)=2
A(2,1)=2
A(2,2)=2
A(2,3)=2
A(3,1)=2
A(3,2)=2
A(3,3)=2
disp('Modified Matrix')
disp(A)
matlab/output.xml
manual code ready 0.4 matrix A 3×3 3 3 double 1 2 3
4 5 6
7 8 9
double double [[{"value":"{\"value\":\"1\"}"},{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"3\"}"}]] 1 matrix A 3×3 3 3 double 2 2 3
4 5 6
7 8 9
double double [[{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"3\"}"}]] 2 matrix A 3×3 3 3 double 2 2 3
4 5 6
7 8 9
double double [[{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"3\"}"}]] 3 matrix A 3×3 3 3 double 2 2 2
4 5 6
7 8 9
double double [[{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"}]] 4 matrix A 3×3 3 3 double 2 2 2
2 5 6
7 8 9
double double [[{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"}]] 5 matrix A 3×3 3 3 double 2 2 2
2 2 6
7 8 9
double double [[{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"}]] 6 matrix A 3×3 3 3 double 2 2 2
2 2 2
7 8 9
double double [[{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"}]] 7 matrix A 3×3 3 3 double 2 2 2
2 2 2
2 8 9
double double [[{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"}]] 8 matrix A 3×3 3 3 double 2 2 2
2 2 2
2 2 9
double double [[{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"}]] 9 matrix A 3×3 3 3 double 2 2 2
2 2 2
2 2 2
double double [[{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"2\"}"}]] 10 text Modified Matrix
false false 11 text 2 2 2
2 2 2
2 2 2
false false 12 true false A = [1 2 3;4 5 6;7 8 9] 0 0 0 0 false false A(1,1)=2 %Replace all elements in A to 2 1 1 1 1 false false A(1,2)=2 2 2 2 2 false false A(1,3)=2 3 3 3 3 false false A(2,1)=2 4 4 4 4 false false A(2,2)=2 5 5 5 5 false false A(2,3)=2 6 6 6 6 false false A(3,1)=2 7 7 7 7 false false A(3,2)=2 8 8 8 8 false false A(3,3)=2 9 9 9 9 false false disp('Modified Matrix') 10 10 10 10 false true disp(A) 11 11 11 11
metadata/coreProperties.xml
2020-04-16T15:39:35Z 2020-04-16T15:44:35Z
metadata/mwcoreProperties.xml
application/vnd.mathworks.matlab.code MATLAB Code R2020a
metadata/mwcorePropertiesExtension.xml
9.8.0.1298242 4d266bd0-3fd5-4818-a4ab-76e11cba79b3
metadata/mwcorePropertiesReleaseInfo.xml

9.8.0.1323502
R2020a

Feb 25 2020
3410093040
Ex4.pdf
A = [1 2 3;4 5 6;7 8 9]
A = 3×3
1 2 3
4 5 6
7 8 9
A(1,1)=2 %Replace all elements in A to 2
A = 3×3
2 2 3
4 5 6
7 8 9
A(1,2)=2
A = 3×3
2 2 3
4 5 6
7 8 9
A(1,3)=2
A = 3×3
2 2 2
4 5 6
7 8 9
A(2,1)=2
A = 3×3
2 2 2
2 5 6
7 8 9
A(2,2)=2
A = 3×3
2 2 2
2 2 6
7 8 9
A(2,3)=2
A = 3×3
2 2 2
2 2 2
7 8 9
A(3,1)=2
A = 3×3
2 2 2
2 2 2
2 8 9
A(3,2)=2
A = 3×3
2 2 2
2 2 2
1
2 2 9
A(3,3)=2
A = 3×3
2 2 2
2 2 2
2 2 2
disp('Modified Matrix')
Modified Matrix
disp(A)
2 2 2
2 2 2
2 2 2
2
Ex5.mlx
[Content_Types].xml

_rels/.rels

matlab/document.xml
disp('B Matrix')
B = [6 2 1;4 2 7;8 3 5] %B Matrix
disp('Modified B Matrix')
B(B>3)=0 %Replace all elements greater than 3 in B to be 0
matlab/output.xml
manual code ready 0.4 text B Matrix
false false 1 matrix B 3×3 3 3 double 6 2 1
4 2 7
8 3 5
double double [[{"value":"{\"value\":\"6\"}"},{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"1\"}"}]] 2 text Modified B Matrix
false false 3 matrix B 3×3 3 3 double 0 2 1
0 2 0
0 3 0
double double [[{"value":"{\"value\":\"0\"}"},{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"1\"}"}]] 4 true false disp('B Matrix') 0 0 0 0 false false B = [6 2 1;4 2 7;8 3 5] %B Matrix 1 1 1 1 false false disp('Modified B Matrix') 2 2 2 2 false true B(B>3)=0 %Replace all elements greater than 3 in B to be 0 3 3 3 3
metadata/coreProperties.xml
2020-04-16T15:51:41Z 2020-04-16T15:54:47Z
metadata/mwcoreProperties.xml
application/vnd.mathworks.matlab.code MATLAB Code R2020a
metadata/mwcorePropertiesExtension.xml
9.8.0.1298242 833b991c-2669-4111-9243-7316a3a43caa
metadata/mwcorePropertiesReleaseInfo.xml

9.8.0.1323502
R2020a

Feb 25 2020
3410093040
Ex5.pdf
disp('B Matrix')
B Matrix
B = [6 2 1;4 2 7;8 3 5] %B Matrix
B = 3×3
6 2 1
4 2 7
8 3 5
disp('Modified B Matrix')
Modified B Matrix
B(B>3)=0 %Replace all elements greater than 3 in B to be 0
B = 3×3
0 2 1
0 2 0
0 3 0
1
Ex6.mlx
[Content_Types].xml

_rels/.rels

matlab/document.xml
C = [1 1 1;1 0 1;1 1 1]
s = [3,3]
a = find(C)
b = length(a)
disp('linear index of element equal to 0')
for i = 1:9
if i ~= a
disp(i)
disp('Subscript index')
[p,q] = ind2sub(s,i) %linear index to subscript index
disp([p,q])
end
end
matlab/output.xml
manual code ready 0.4 matrix C 3×3 3 3 double 1 1 1
1 0 1
1 1 1
double double [[{"value":"{\"value\":\"1\"}"},{"value":"{\"value\":\"1\"}"},{"value":"{\"value\":\"1\"}"}]] 1 matrix s 1×2 1 2 double 3 3
double double [[{"value":"{\"value\":\"3\"}"},{"value":"{\"value\":\"3\"}"}]] 2 matrix a 8×1 8 1 double 1
2
3
4
6
7
8
9
double double [[{"value":"{\"value\":\"1\"}"},{"value":"{\"value\":\"2\"}"},{"value":"{\"value\":\"3\"}"},{"value":"{\"value\":\"4\"}"},{"value":"{\"value\":\"6\"}"},{"value":"{\"value\":\"7\"}"},{"value":"{\"value\":\"8\"}"},{"value":"{\"value\":\"9\"}"}]] 3 variable b 8 1 1 4 text linear index of element equal to 0
false false 5 text 5
false false 8 text Subscript index
false false 9 variable p 2 1 1 10 variable q 2 1 1 10 text 2 2
false false 11 true false C = [1 1 1;1 0 1;1 1 1] 0 0 0 0 false false s = [3,3] 1 1 1 1 false false a = find(C) 2 2 2 2 false false b = length(a) 3 3 3 3 false false disp('linear index of element equal to 0') 4 4 4 4 false true for i = 1:9
if i ~= a
disp(i)
disp('Subscript index')
[p,q] = ind2sub(s,i)
disp([p,q])
end
end 5 5 12 5 6 7 8 9
metadata/coreProperties.xml
2020-04-16T13:19:33Z 2020-04-16T14:29:47Z
metadata/mwcoreProperties.xml
application/vnd.mathworks.matlab.code MATLAB Code R2020a
metadata/mwcorePropertiesExtension.xml
9.8.0.1298242 952e5d25-c982-42a7-b673-848d2a5a27e4
metadata/mwcorePropertiesReleaseInfo.xml

9.8.0.1323502
R2020a

Feb 25 2020
3410093040
Ex6.pdf
C = [1 1 1;1 0 1;1 1 1]
C = 3×3
1 1 1
1 0 1
1 1 1
s = [3,3]
s = 1×2
3 3
a = find(C)
a = 8×1
1
2
3
4
6
7
8
9
b = length(a)
b = 8
disp('linear index of element equal to 0')
linear index of element equal to 0
for i = 1:9
if i ~= a
disp(i)
disp('Subscript index')
[p,q] = ind2sub(s,i) %linear index to subscript index
disp([p,q])
end
end
5
Subscript index
p = 2
q = 2
2 2
1
Ex7.mlx
[Content_Types].xml

_rels/.rels

matlab/document.xml
D = [0 0 0;0 0 0;0 0 2]
disp('Smallest element of D')
x = min(D(:))
disp('Linear index of non zero elements of D')
y = find(D)
matlab/output.xml
manual code ready 0.4 matrix D 3×3 3 3 double 0 0 0
0 0 0
0 0 2
double double [[{"value":"{\"value\":\"0\"}"},{"value":"{\"value\":\"0\"}"},{"value":"{\"value\":\"0\"}"}]] 1 text Smallest element of D
false false 2 variable x 0 1 1 3 text Linear index of non zero elements of D
false false 4 variable y 9 1 1 5 true false D = [0 0 0;0 0 0;0 0 2] 0 0 0 0 false false disp('Smallest element of D') 1 1 1 1 false false x = min(D(:)) 2 2 2 2 false false disp('Linear index of non zero elements of D') 3 3 3 3 false true y = find(D) 4 4 4 4
metadata/coreProperties.xml
2020-04-16T12:42:42Z 2020-04-16T13:05:27Z
metadata/mwcoreProperties.xml
application/vnd.mathworks.matlab.code MATLAB Code R2020a
metadata/mwcorePropertiesExtension.xml
9.8.0.1298242 3064b517-8ca3-460b-963e-b3330b9a376d
metadata/mwcorePropertiesReleaseInfo.xml

9.8.0.1323502
R2020a

Feb 25 2020
3410093040
Ex7.pdf
D = [0 0 0;0 0 0;0 0 2]
D = 3×3
0 0 0
0 0 0
0 0 2
disp('Smallest element of D')
Smallest element of D
x = min(D(:))
x = 0
disp('Linear index of non zero elements of D')
Linear index of non zero elements of D
y = find(D)
y = 9
1
Ex8.mlx
[Content_Types].xml

_rels/.rels

matlab/document.xml
x = 1:1:10;
y = 3 * sin(x+2) + 1;
disp('x y');
for j = 1:10
fprintf("%f %f\n",x(j),y(j));
end
plot(x,y);
xlabel('x');
ylabel('y');
grid on
matlab/output.xml
manual code ready 0.4 text x y
false false 3 text 1.000000 1.423360
2.000000 -1.270407
3.000000 -1.876773
4.000000 0.161754
5.000000 2.970960
6.000000 3.968075
7.000000 2.236355
8.000000 -0.632063
9.000000 -1.999971
10.000000 -0.609719
false 5 figure 8d7dfdac-9daf-4f13-ae30-92dc463add89...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here