Discrete StructureMATLAB Using MATLAB to develop a program t

Discrete Structure`MATLAB

Using MATLAB to develop a program to request a list of between one and five elements which are alpha characters. Produce the Power Set which will have the following output:
{a,b,c,d,e}
Your output would be:
The subsets with cardinality zero are: {}
The subsets with cardinality one are:{a},{b},{c,}{d},{e}
The subsets with cardinality two are: {a,b},{a,c},{a,d},{a,e},{b,c},{b,d},{b,e},{c,d},{c,e},{d,e}
The subsets with cardinality three are:{a,b,c},{a,b,d},{a,b,e},{a,c,d},{a,c,e},{a,d,e},{b,c,d},{b,c,e},{b,d,e},{c,d,e}
The subsets with cardinality four are: {a,b,c,d},{a,b,c,e},{a,b,d,e},{a,c,d,e},{b,c,d,e}
The subsets with cardinality five are: {a,b,c,e,d}

If the initial set fewer than five elements, your output will only display the subsets of size up to and including the cardinality of the original set.


____________________________________________
Thank you.

Solution

clc
clear all
close all
x=input(\'Enter alpha characters x between one and five elements:\',\'s\');
l=length(x);
if l>5
disp(\'The subsets of size up to and including the cardinality of the original set\')
break
end

fprintf(\'The subxs with cardinality one are:\')
for i=1:l
fprintf(\'{%c},\',char(x(i)))
end

if l>=2
fprintf(\'\ The subxs with cardinality two are:\')
for i=1:l
k=i+1;
for j=k:l
fprintf(\'{%c,%c},\',char(x(i)),char(x(j)))
end
end
end

if l>=3
fprintf(\'\ The subxs with cardinality three are:\')
for i=1:l
k=i+1;
for j=k:l
m=j+1;
for n=m:l
fprintf(\'{%c,%c,%c},\',char(x(i)),char(x(j)),char(x(n)))
end
end
end
end

if l>=4
fprintf(\'\ The subxs with cardinality four are:\')
for i=1:l
k=i+1;
for j=k:l
m=j+1;
for n=m:l
p=n+1;
for y=p:l
fprintf(\'{%c,%c,%c,%c},\',char(x(i)),char(x(j)),char(x(n)),char(x(y)))
end
end
end
end
end

if l>=5
fprintf(\'\ The subsets with cardinality four are:\')
fprintf(\'{%c,%c,%c,%c,%c}\ \',char(x(1)),char(x(2)),char(x(3)),char(x(4)),char(x(5)))
end

OUTPUT is,

Enter alpha characters x between one and five elements:abcde
The subxs with cardinality one are:{a},{b},{c},{d},{e},
The subxs with cardinality two are:{a,b},{a,c},{a,d},{a,e},{b,c},{b,d},{b,e},{c,d},{c,e},{d,e},
The subxs with cardinality three are:{a,b,c},{a,b,d},{a,b,e},{a,c,d},{a,c,e},{a,d,e},{b,c,d},{b,c,e},{b,d,e},{c,d,e},
The subxs with cardinality four are:{a,b,c,d},{a,b,c,e},{a,b,d,e},{a,c,d,e},{b,c,d,e},
The subsets with cardinality four are:{a,b,c,d,e}
>>

Enter alpha characters x between one and five elements:abcdef
The subsets of size up to and including the cardinality of the original set

Discrete Structure`MATLAB Using MATLAB to develop a program to request a list of between one and five elements which are alpha characters. Produce the Power Set
Discrete Structure`MATLAB Using MATLAB to develop a program to request a list of between one and five elements which are alpha characters. Produce the Power Set

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site