How I can solve these problems in MATLAB? 1. Find the elements of F less than 50
ID: 669083 • Letter: H
Question
How I can solve these problems in MATLAB?
1. Find the elements of F less than 50 and greater or equal to 10. What are their indices?
2. Multiply first row of A by 5, call the equivalent matrix X and then calculate its determinant, and compare the answer with the determinant of 5A.
3. What is the element-wise multiplication of A and B? What about F and D?
4. What is the smallest, largest, and average value of A? What about B?
5. Find the elements of A not equal to 3 nor 2. What are their indices?
6. Calculate the determinants of I5
Explanation / Answer
Program:
A = [1 0 2;3 1 4;5 0 2];
B = [5 0 2;3 1 4;1 0 2];
F = [34 0 12;15 1 4;1 0 2];
D = [1 0 2;3 1 4;5 0 2];
%Finding the elements of F less than 50 and greater or equal to 10 and their indices?
fprintf('Elements in F less than 50 and greater or equal to 10, with indices ');
for i=1:numel(F)
if(F(i)<50 && F(i)>=10)
fprintf('Element %d is at index %d ',F(i),i);
end
end
%Find the elements of A not equal to 3 nor 2. What are their indices?
fprintf('Elements in A not equal to 3 nor 2, with indices ');
for i=1:numel(A)
if(A(i)~=3 || A(i)~=2)
fprintf('Element %d is at index %d ',A(i),i);
end
end
% Multiply first row of A by 5, call the equivalent matrix X and then calculate its
% determinant, and compare the answer with the determinant of 5A.
fprintf('Compare, First row of A mul 5 with determinant of 5A ');
Det = round(poly(5*A));
X=5*A(1,:);
tf = isequal(X,Det);
if(tf==true)
fprintf('Both are equal ');
else
fprintf('Both are not equal ');
end
%What is the element-wise multiplication of A and B? What about F and D?
fprintf('element-wise multiplication of A and B ');
C=A.*B;
disp(C);
fprintf('element-wise multiplication of F and D ');
G=F.*D;
disp(G);
%What is the smallest, largest, and average value of A? What about B?
[Min] = min(A(:));
fprintf('Smallest Element of A:%d ',Min);
[Max] = max(A(:));
fprintf('Largest Element of A:%d ',Max);
% Get the size of the count matrix
[n,p] = size(A);
% Compute the mean of each column
mu = mean2(A);
% Create a matrix of mean values by
% replicating the mu vector for n rows
MeanMat = repmat(mu,n,1);
% Subtract the column mean from each element
% in that column
mx = A - MeanMat;
fprintf('Average value of A:%d ',mx);
[Min] = min(B(:));
fprintf('Smallest Element of B:%d ',Min);
[Max] = max(B(:));
fprintf('Largest Element of B:%d ',Max);
mx=mean2(B,3);
fprintf('Average value of B:%d ',mx);
Output:
>> Matrix
Elements in F less than 50 and greater or equal to 10, with indices
Element 34 is at index 1
Element 15 is at index 2
Element 12 is at index 5
Elements in A not equal to 3 nor 2, with indices
Element 1 is at index 1
Element 3 is at index 2
Element 0 is at index 3
Element 1 is at index 4
Element 2 is at index 5
Element 4 is at index 6
Compare, First row of A mul 5 with determinant of 5A
Error using poly (line 31)
Argument must be a vector or a square matrix.
Error in Matrix (line 25)
Det = round(poly(5*A));
>> Matrix
Elements in F less than 50 and greater or equal to 10, with indices
Element 34 is at index 1
Element 15 is at index 2
Element 12 is at index 7
Elements in A not equal to 3 nor 2, with indices
Element 1 is at index 1
Element 3 is at index 2
Element 5 is at index 3
Element 0 is at index 4
Element 1 is at index 5
Element 0 is at index 6
Element 2 is at index 7
Element 4 is at index 8
Element 2 is at index 9
Compare, First row of A mul 5 with determinant of 5A
Error using -
Matrix dimensions must agree.
Error in Matrix (line 27)
Y=A-X;
>> Matrix
Elements in F less than 50 and greater or equal to 10, with indices
Element 34 is at index 1
Element 15 is at index 2
Element 12 is at index 7
Elements in A not equal to 3 nor 2, with indices
Element 1 is at index 1
Element 3 is at index 2
Element 5 is at index 3
Element 0 is at index 4
Element 1 is at index 5
Element 0 is at index 6
Element 2 is at index 7
Element 4 is at index 8
Element 2 is at index 9
Compare, First row of A mul 5 with determinant of 5A
Both are not equal
element-wise multiplication of A and B
5 0 4
9 1 16
5 0 4
element-wise multiplication of F and D
34 0 24
45 1 16
5 0 4
Smallest Element of A:0
Smallest Element of A:1
Smallest Element of A:0
Largest Element of A:2
Largest Element of A:4
Largest Element of A:5
Average value of A:1
Average value of A:2.666667e+00
Average value of A:2.333333e+00
Smallest Element of B:0
Smallest Element of B:1
Smallest Element of B:0
Largest Element of B:5
Largest Element of B:4
Largest Element of B:2
Subscript indices must either be real positive integers or logicals.
Error in Matrix (line 54)
mean=mean(B,2);
>> Matrix
Elements in F less than 50 and greater or equal to 10, with indices
Element 34 is at index 1
Element 15 is at index 2
Element 12 is at index 7
Elements in A not equal to 3 nor 2, with indices
Element 1 is at index 1
Element 3 is at index 2
Element 5 is at index 3
Element 0 is at index 4
Element 1 is at index 5
Element 0 is at index 6
Element 2 is at index 7
Element 4 is at index 8
Element 2 is at index 9
Compare, First row of A mul 5 with determinant of 5A
Both are not equal
element-wise multiplication of A and B
5 0 4
9 1 16
5 0 4
element-wise multiplication of F and D
34 0 24
45 1 16
5 0 4
Smallest Element of A:1
Smallest Element of A:3
Smallest Element of A:5
Smallest Element of A:0
Smallest Element of A:1
Smallest Element of A:0
Smallest Element of A:2
Smallest Element of A:4
Smallest Element of A:2
Largest Element of A:1
Largest Element of A:3
Largest Element of A:5
Largest Element of A:0
Largest Element of A:1
Largest Element of A:0
Largest Element of A:2
Largest Element of A:4
Largest Element of A:2
Subscript indices must either be real positive integers or logicals.
Error in Matrix (line 47)
mean=mean(A,3);
>> Matrix
Elements in F less than 50 and greater or equal to 10, with indices
Element 34 is at index 1
Element 15 is at index 2
Element 12 is at index 7
Elements in A not equal to 3 nor 2, with indices
Element 1 is at index 1
Element 3 is at index 2
Element 5 is at index 3
Element 0 is at index 4
Element 1 is at index 5
Element 0 is at index 6
Element 2 is at index 7
Element 4 is at index 8
Element 2 is at index 9
Compare, First row of A mul 5 with determinant of 5A
Both are not equal
element-wise multiplication of A and B
5 0 4
9 1 16
5 0 4
element-wise multiplication of F and D
34 0 24
45 1 16
5 0 4
Smallest Element of A:1
Smallest Element of A:3
Smallest Element of A:5
Smallest Element of A:0
Smallest Element of A:1
Smallest Element of A:0
Smallest Element of A:2
Smallest Element of A:4
Smallest Element of A:2
Largest Element of A:1
Largest Element of A:3
Largest Element of A:5
Largest Element of A:0
Largest Element of A:1
Largest Element of A:0
Largest Element of A:2
Largest Element of A:4
Largest Element of A:2
Subscript indices must either be real positive integers or logicals.
Error in Matrix (line 51)
mu = mean(A);
>> Matrix
Elements in F less than 50 and greater or equal to 10, with indices
Element 34 is at index 1
Element 15 is at index 2
Element 12 is at index 7
Elements in A not equal to 3 nor 2, with indices
Element 1 is at index 1
Element 3 is at index 2
Element 5 is at index 3
Element 0 is at index 4
Element 1 is at index 5
Element 0 is at index 6
Element 2 is at index 7
Element 4 is at index 8
Element 2 is at index 9
Compare, First row of A mul 5 with determinant of 5A
Both are not equal
element-wise multiplication of A and B
5 0 4
9 1 16
5 0 4
element-wise multiplication of F and D
34 0 24
45 1 16
5 0 4
Smallest Element of A:0
Largest Element of A:5
Subscript indices must either be real positive integers or logicals.
Error in Matrix (line 51)
mu = mean(A);
>> Matrix
Elements in F less than 50 and greater or equal to 10, with indices
Element 34 is at index 1
Element 15 is at index 2
Element 12 is at index 7
Elements in A not equal to 3 nor 2, with indices
Element 1 is at index 1
Element 3 is at index 2
Element 5 is at index 3
Element 0 is at index 4
Element 1 is at index 5
Element 0 is at index 6
Element 2 is at index 7
Element 4 is at index 8
Element 2 is at index 9
Compare, First row of A mul 5 with determinant of 5A
Both are not equal
element-wise multiplication of A and B
5 0 4
9 1 16
5 0 4
element-wise multiplication of F and D
34 0 24
45 1 16
5 0 4
Smallest Element of A:0
Largest Element of A:5
Subscript indices must either be real positive integers or logicals.
Error in Matrix (line 51)
mu = mean(A);
>> Matrix
Elements in F less than 50 and greater or equal to 10, with indices
Element 34 is at index 1
Element 15 is at index 2
Element 12 is at index 7
Elements in A not equal to 3 nor 2, with indices
Element 1 is at index 1
Element 3 is at index 2
Element 5 is at index 3
Element 0 is at index 4
Element 1 is at index 5
Element 0 is at index 6
Element 2 is at index 7
Element 4 is at index 8
Element 2 is at index 9
Compare, First row of A mul 5 with determinant of 5A
Both are not equal
element-wise multiplication of A and B
5 0 4
9 1 16
5 0 4
element-wise multiplication of F and D
34 0 24
45 1 16
5 0 4
Smallest Element of A:0
Largest Element of A:5
Subscript indices must either be real positive integers or logicals.
Error in Matrix (line 51)
mu = mean(A);
>> Matrix
Elements in F less than 50 and greater or equal to 10, with indices
Element 34 is at index 1
Element 15 is at index 2
Element 12 is at index 7
Elements in A not equal to 3 nor 2, with indices
Element 1 is at index 1
Element 3 is at index 2
Element 5 is at index 3
Element 0 is at index 4
Element 1 is at index 5
Element 0 is at index 6
Element 2 is at index 7
Element 4 is at index 8
Element 2 is at index 9
Compare, First row of A mul 5 with determinant of 5A
Both are not equal
element-wise multiplication of A and B
5 0 4
9 1 16
5 0 4
element-wise multiplication of F and D
34 0 24
45 1 16
5 0 4
Smallest Element of A:0
Largest Element of A:5
Undefined function or variable 'mean2'.
Error in Matrix (line 51)
mu = mean2(A);
>> Matrix
Elements in F less than 50 and greater or equal to 10, with indices
Element 34 is at index 1
Element 15 is at index 2
Element 12 is at index 7
Elements in A not equal to 3 nor 2, with indices
Element 1 is at index 1
Element 3 is at index 2
Element 5 is at index 3
Element 0 is at index 4
Element 1 is at index 5
Element 0 is at index 6
Element 2 is at index 7
Element 4 is at index 8
Element 2 is at index 9
Compare, First row of A mul 5 with determinant of 5A
Both are not equal
element-wise multiplication of A and B
5 0 4
9 1 16
5 0 4
element-wise multiplication of F and D
34 0 24
45 1 16
5 0 4
Smallest Element of A:0
Largest Element of A:5
Smallest Element of B:0
Largest Element of B:5
Undefined function or variable 'mean2'.
Error in Matrix (line 54)
mx=mean2(B,3);
>> Matrix
Elements in F less than 50 and greater or equal to 10, with indices
Element 34 is at index 1
Element 15 is at index 2
Element 12 is at index 7
Elements in A not equal to 3 nor 2, with indices
Element 1 is at index 1
Element 3 is at index 2
Element 5 is at index 3
Element 0 is at index 4
Element 1 is at index 5
Element 0 is at index 6
Element 2 is at index 7
Element 4 is at index 8
Element 2 is at index 9
Compare, First row of A mul 5 with determinant of 5A
Both are not equal
element-wise multiplication of A and B
5 0 4
9 1 16
5 0 4
element-wise multiplication of F and D
34 0 24
45 1 16
5 0 4
Smallest Element of A:0
Largest Element of A:5
Smallest Element of B:0
Largest Element of B:5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.