Sunteți pe pagina 1din 31

if then when?

While do you?

What for

Whats your function

And the plot thickens

Easy Medium Hard

Easy Medium Hard

Easy Medium Hard

Easy Medium Hard

Easy Medium Hard

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

Whats your function


Mohammad has been studying abroad in the US for only a few week, which is not a long enough time that he keeps running into trouble of understanding the Fahrenheit system, a common temperature unit in the US. As a result, he constantly asks his roommate, Adam, to check on the temperature outside. Adam is getting tired of converting to and Mohammad is such a lazy student that he doesnt even bother doing it himself. Therefore, Adam decides to give Mohammad a much faster way to know the corresponding Celcius degree given any Fahrenheit temperature: a convenient MATLAB function. What does Adam have to write for this MATLAB function?

Easy

Whats your function


Analysis: Function template with output(s), inputs, and a function name Output: Celcius (C) Input: Fahrentheit (F) Function name: temp (or anything without any space in between) Use the conversion formula: 5 32 = 9 Function:
function C = temp(F) %Conversion of degF to degC C = 5*(F-32)/9 end

Easy

Answer

Whats your function


.3

Medium

Whats your function

Medium

Answer

Whats your function


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

Whats your function

Hard

Answer

And the Plot thickens


Nicole is working on her math homework assignment. She is then stuck at the question that asks her to compare 3 and . Nicole decides to seek help from her engineering-major friend Joey. Joey looks at the problem and is also having a hard time solving it. However, he quickly thinks of a powerful tool that he has learned recently: MATLAB. Joey opens MATLAB and attempts to visualize the problem because he believes graphical interpretations usually give many useful information. And his belief is well paid off with him and Nicole finally seeing the true behaviors of the two functions and being able to compare them with ease. What has Joey done?

Easy

And the Plot thickens


Analysis: Symbolic plot (ezplot) vs. numerical plot (plot) Excel can be used as a reference Script:
x = 0:0.01:6; y1 = x.^3; %vs. x^3 y2 = exp(x); plot(x,y1,x,y2) title(x^3 vs. e^x) %note that ^ gives superscript effect xlabel(x) ylabel(y) legend(y1 = x^3,y2 = e^x)

Easy

Answer

And the Plot thickens


5.3

Medium

And the Plot thickens

Medium

Answer

And the Plot thickens


5.18

Hard

And the Plot thickens

Hard

Answer

S-ar putea să vă placă și