done in matlab write the code for all problems ECE 72: Introduction to Electrica
ID: 3869777 • Letter: D
Question
done in matlab write the code for all problems
Explanation / Answer
clear all; close all;
%Solution 1
B = repmat(5, [4 4 4]);
sum = 0;
for i=1:4
m=B(:,:,i);
for j=1:4
for k=1:5
sum = sum + m(i,j);
end
end
end
%Solution 2
ll = 1;
ul = 50;
r = (ul-ll).*rand(100,1) + ll;
a = 1;
b = 1;
dig = 1;
while(dig < 100)
numHere = r(dig);
if (numHere > 40)
a = a + b;
elseif (numHere < 10)
b = a.*b;
elseif (numHere == 25)
a = a + a
else
a = a + 1;
b = b + 1;
end
dig = dig + 1;
end
%Solution 3
ll = 1;
ul = 50;
r = (ul-ll).*rand(100,1) + ll;
a = 1;
b = 1;
dig = 1;
while(dig < 100)
numHere = r(dig);
switch(numHere)
case (numHere > 40)
a = a + b;
case (numHere < 10)
b = a.*b;
case (numHere == 25)
a = a + a
otherwise
a = a + 1;
b = b + 1;
end
dig = dig + 1;
end
a
b
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.