Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a)Use a loop to determine how many years it will take 100 grams of an unknown su

ID: 3915436 • Letter: A

Question

a)Use a loop to determine how many years it will take 100 grams of an unknown substance to decay below 5 grams. The substance decays at a rate of 1/3 of its value every year. After year 1 : 66.6 grams remain, after year 2 : 44.4 grams remain, etc…

b)Use the randifunction to generate a single random number between the range 1 and 50. Check if that random integer equals 15. If it does not, then generate another random number. Continue this until the random number equals 15. Display how many incorrect random numbers were generated.

c )Flip the following array using ONLY loops (no reshape or transpose)

  t

Explanation / Answer

ScreenShot

-----------------------------------------------------------------------------------------------

Question a)

Code:-

%initialize variables for year count and substance weight
year=0;
compound=100;
%Loop to determine decay
while compound>=5
%each year reduce 1/3
compound=compound-(compound/3);
%Increase year
year=year+1;
end
%Display output
fprintf("Number of years needed to decay <5gm= %d",year)

Output:-

Number of years needed to decay <5gm= 8

-------------------------------------------------------------------------------------

Question b:-

Code:-

%Variable for number of times not 15
count=0;
%Random number between 1-50
num=randi(50);
%loop check for 15
while(num!=15)
count=count+1;
num=randi(50);
end
%Print the number of times not 15
fprintf("Incorrect random number generated= %d",count)

Output:-

Incorrect random number generated= 17

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote