Documente Academic
Documente Profesional
Documente Cultură
While do you?
What for
If then when?
Nick is taking CHEE 1331 for his first time. He doesnt even need the course but the curriculum forbids him to skip it. Its not that he doesnt like it but he is just confident in his programming skills (a little over confident). Thus, he pays less and less attention to the course material and take-home assignments. Nick starts to score unexpectedly low in the tests. When it comes to the last exam, he calculates that he needs an 67.8 to get a C and a 93.9 to get a B on the final. Let N be Nicks final exam grade, and N be given by you (assume that you were a god and you had the power to set Nicks exam grade to be anything). Write a script to determine Nicks fate in this course, given that he is desperate for a C, or else his dad will kick his butt for 100 times. Note that the highest possible score on the final is 100.
Easy
If then when?
Analysis: N is given (by you) N < 67.8: Butt kicked! 67.8 < N < 93.9: grade C 93.9 < N < 100: grade B N > 100: Wow, this god just breaks the rule. Thiss impossible.
Easy
Script:
N = input('Nicks final exam grade is: '); if N < 67.8 fprintf('Nick fails \n') elseif and((N >= 67.8),(N < 93.9)) == 1 fprintf('Nick gets a C \n') else fprintf('Nick gets a B \n') fprintf('Wow! \n') end
Answer
If then when?
Write a script to check if a number is divisible by 7 or not, using the following 2 methods. a) mod function that gives the remainder of any division. b) floor function that rounds a real number to an integer that is less than or equal that number.
Your script shall be used to check for the divisibility of a number by any divisor by only a slight modification.
Medium
If then when?
Analysis: Definition of being divisible: remainder is zero If the quotient of A/B is exactly the floor of itself then A is divisible by B. Script:
A = input(Give a number: '); if mod(A,7) == 0 (or if floor(A/7) == A/7) fprintf(A is divisible by 7 \n') else fprintf('A is not divisible by 7 \n ') end
Medium
Answer
If then when?
4.20
Hard
Optional
If then when?
Analysis: Two formulas for x, which to use depends on d. Script:
function x = package(W,k1,k2,d); if W < k1*d x = W/k1; else x = (W+2*k2*d)/(k1+2*k2); end disp(The distance traveled is:) disp(x) end
Hard
Answer
While do you?
Alice is working on an experiment. She is given a beaker of starch solution and a pipet that can pump a fixed volume of 0.2 mL of iodine. What happens if she adds iodine to starch solution? A light source is shone through the beaker and the intensity of the transmitted beam is measured in lumens (lm) unit. When no iodine is present, it measures 500 lm. Alices advisor wants her to calculate the total amount of iodine required to reach a measurement right below 200 lm, given that the intensity is dependent on the added volume of iodine via the following relationship: = 500 0.353 Where I represents the light intensity (lm) and V indicates the added volume of iodine (mL). Note: the given expression is made up for the purpose of this problem only. One should not use it as a reference.
Easy
While do you?
Analysis: Easily solved: = ln . But how about While loop? 0.353 500 Condition to do the loop: I > 200. Exit whenever I drops below 200 Keep calculating the intensity and feed it back to the condition Script:
%Initialize the variables V = 0; I = 500; %While loop while I >= 200 V = V + 0.2; I = 500*exp(-0.353*V); end %Output result fprintf('Total amount of iodine required: %0.1f',V) fprintf(' mL \n');
1 200
Easy
Answer
While do you?
Write a script to check if a number is divisible by 4 or not. Can your script be modified only slightly (within a few characters) to check for the divisibility of a number by 7? How about any divisor?
Medium
While do you?
Medium
Answer
While do you?
Write a script to check if a number is divisible by 4 or not. Can your script be modified only slightly (within a few characters) to check for the divisibility of a number by 7? How about any divisor?
Hard
While do you?
Hard
Answer
What for
Jimmy is assigned to measure the relative amount of cancer cells in 500 mice (in percent) after they are treated with an experimental cancer treatment fluid. It is widely believed that if the amount of cancer cells present in the mice that has the most malignant tumor is less than 10% then the treatment is accepted for clinical trial. Suppose that Jimmy has already recorded all the data needed from the mice. However, the size of data is so large that he decides to turn to you for some computational help. Fortunately, you have just learned the powerful for loop today. How would you apply the loop to help Jimmy on this?
Note: Let C be the data vector
Easy
What for
Analysis: Find the maximum value using for loop Compare the max to 10% Script:
%For loop Max = C(1); for i = 1:500 if C(i) >= Max Max = C(i); end end %Output result if Max < 10 fprintf(Ready for clinical trial') else fprintf(Not ready for clinical trial) end
Easy
Answer
What for
Compute the sum of the cubes of the first 100 positive integers.
Medium
What for
Medium
Answer
What for
4.23
Hard
What for
Hard
Answer
Easy
Easy
Answer
Medium
Medium
Answer
Hard
Hard
Answer
Easy
Easy
Answer
Medium
Medium
Answer
Hard
Hard
Answer