Solving 2nd part of minimax question
Show older comments
Good day, Please I've been stuck on this assignment for awhile now, i got the second part but the first part can't seem to make it work with random numbers. Had an eureka with 'mmm' and it was thrilling but my assignment is 'over' overdue and i really need a guide to solve 'mmr' properly. i'll greatly appreciate any help. Thank you
Here's what i've achieved so far.
mmr works but not with random numbers and it seems cumbersome.
function [mmr,mmm] = minimaxTrial(M)
A = ([M]);
A_max = max(A,[],'all');
A_min = min (A,[],'all');
mmm = (A_max - A_min);
[row,col] = size(A);
C_1 = (A(1,1:col));
C_2 = (A(2,1:col));
C_3 = (A(3,1:col));
C_4 = (A(n,1:col));
M1 = max(C_1) - min(C_1);
M2 = max(C_2) - min(C_2);
M3 = max(C_3) - min(C_3);
M4 = max(c_4) - min(C_4);
mmr =[M1, M2, M3, M4];
end
8 Comments
Turlough Hughes
on 15 Dec 2019
It's not clear what you want to do. Anyway, the min and max function will return the min/max for each column or for each row of your input matrix if you have the third input as 1 or 2 respectively. Also instead of A(1,1:col) you can simply write A(1,:), even though you don't actually need those lines.
Sarah Majin
on 15 Dec 2019
John D'Errico
on 15 Dec 2019
Edited: John D'Errico
on 15 Dec 2019
Remember that when you ask for help because something does not work properly, if you show us ONLY the code, then we cannot know what you really need to get as a result. Just telling us this is the second part of a minimax question does not help, because we don't see the question, and we are not taking your course. Showing the code you wrote is hugely important, just not quite enough.
I will add that the line:
A = ([M]);
is comepletely irrelevant to anything. It does nothing except use CPU cycles.
It looks like the question in respect to mmm is to return the difference between the overall largest and smallest elements in the matrix.
Is mmr supposed to be somehow related to that, perhaps applying only to the rows of the matrix?
Turlough Hughes
on 15 Dec 2019
Yes, the last 9 lines can be boiled down to one. Try min(A,[],2), which gives the minimum of each row.
Sarah Majin
on 15 Dec 2019
Sarah Majin
on 15 Dec 2019
Turlough Hughes
on 15 Dec 2019
Madumathi Krishnan
on 11 May 2020
I got the output for that question
Write a function called minimax that takes M, a matrix input argument and returns * mmr, a row vector containing the absolute values of the difference between the maximum and minimum valued elements in each row.* As a second output argument called mmm, it provides the difference between the maximum and minimum element in the entire matrix
function [mmr,mmm]=minimax (M)
mmr=max(M,[],2)'-min(M,[],2)';
c=max(M,[],2);
d=min(M,[],2);
mmm=max(c)-min(d);
end
[mmr, mmm] = minimax([1:4;5:8;9:12])
Accepted Answer
More Answers (2)
ERTIZA HOSSAIN SHOPNIL
on 6 May 2020
function [mmr,mmm]= minimax(x)
A=x';
mmr=max(A)-min(A);
mmm=(max(A,[],'all')-min(A,[],'all'));
end
Naveen Gehlot
on 22 Aug 2020
function [mmr, mmm]= minimax (A)
mmr = [max(A,[],2)- min(A,[],2)]';
mmm = max(A,[],'all')-min(A,[],'all');
OUTPUT
mmr =
3 3 3
mmm =
11
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!