Question: function [SID,Diversity]=Language(numLanguage,E,S,M) all3 = intersect(intersect(E,S),M); only2 = setdiff(union(union(intersect(E,S),intersect(S,M)),intersect(E,M)),all3); only1 = setdiff(setdiff(union(union(E,S),M),only2),all3); switch numLanguage case 3 SID= intersect(intersect(E,S),M); case 2 SID= only2; case 1 SID= only1;
![function [SID,Diversity]=Language(numLanguage,E,S,M) all3 = intersect(intersect(E,S),M); only2 = setdiff(union(union(intersect(E,S),intersect(S,M)),intersect(E,M)),all3); only1 = setdiff(setdiff(union(union(E,S),M),only2),all3);](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3c8150d3a1_50066f3c81498606.jpg)

function [SID,Diversity]=Language(numLanguage,E,S,M)
all3 = intersect(intersect(E,S),M);
only2 = setdiff(union(union(intersect(E,S),intersect(S,M)),intersect(E,M)),all3);
only1 = setdiff(setdiff(union(union(E,S),M),only2),all3);
switch numLanguage
case 3
SID= intersect(intersect(E,S),M);
case 2
SID= only2;
case 1
SID= only1;
end
%probability = 1-length(only1)/length(union(union(E,S),M))
%should be the above formula but there seems to be some incorrect logic in the example case in question
if (length(all3)>=1 || length(only2)>=1)
Diversity=1;
else
Diversity=0;
end
end
Ive tried that code, however the output is SID = 101, and diversity is =1. I want the SID to be [101 , 103] and the diversity to be 0. how can I do that ?
Each student in a class can speak at least one of the languages English, Spanish or Mandarin. We are looking to find out the students who can speak only one language, two languages or all three languages. Using switch-case please write the function Language() that takes as input the variable numLanguage indicating the number of languages that a student can speak and the array of student IDs that can speak numLanguage. The function Language() then returns the IDs of the students who can speak numLanguage and also wether the class is diverse enough or not. A class is defined as being Diverse if the probability of a student talking two languages is more than 50 percent. The function call is: [scoreForYellow, message ] = Language (numLanguage, E,S,M) Input to the function Language is: numLanguage: number of the language we are testing for. An integer number. It can be 1, 2 or 3. E: is the array of integer numbers indicating the IDs of students who speaks English. S: is the array of integer numbers indicating the IDs of students who speaks Spanish M: is the array of integer numbers indicating the IDs of students who speaks Mandarin. Outputs of the function Language) are: SID: is the array of double precision numbers indicating the IDs of students who can speak numLanguage languages Diversity: is logical variable. It's set to one when the probability of speaking two languages is more than 50 percent. Restrictions: Must use switch-case to create array SID and if-else statements for Diversity. For Example: We are testing to see how many students can speak all three languages. On Calling, numLanguage = 3 E=[101, 102, 103, 105, 106] S=[101] M=[101, 103, 104] [SID, Diversity]=Language(numLanguage, E,S,M) Gives output: SID=[101] Diversity = 1 Hint: Please use Matlab built in function union() and intersect() E=[101, 102, 103, 105, 106]; S=[101]; M=[101, 103, 104]; numLanguage=3; [SID, Diversity]=Language (numLanguage, E,S,M) function (SID, Diversity]=Language (numLanguage, E,S,M) switch case 3 SID= case 2 SID= case 1 SID= end if Diversity end end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
