Anda di halaman 1dari 3


Axel POSCHMANN MH1400 Algorithms & Computing I

AY 2012

Lab Questions: First Lab Session

Deadline: 28.08.2012 17:00 SGT
Complete all assignments below. Create a le <yourMatricNo Lab1>.txt and use it to save your answers (the corresponding history log) to those questions below that are marked with an asterisk . These questions are 11 and 14. Once you are done with it, submit the le via edveNTUre. Important!!! The submission system closes at the deadline. Hence after that, you will get no marks for your solution. 1. In the workspace type why and see what happens. Repeat it a couple of times. This is called an easter egg, because it is nonsense hidden by a programmer. There are many such easter eggs hidden in MATLAB, and we will reveal some of them during this lab session. 2. Create a variable to store the atomic weight of Lithium (6.941) 3. Create a variable myage and store your age in it. Subtract 5 from the value of the variable. Add 8 to the value of the variable. 4. Use the built-in function namelengthmax to nd out the maximum number of characters that you can have in an identier name under your version of MATLAB. 5. Explore the format command in more detail. Use help format to nd options. Experiment with format bank to display dollar values. Then type in why again. 6. Find a format option that would result in the following output format: >> 5/16 + 2/7 ans = 67/112 7. The combined resistance RT of three resistors R1 , R2 and R3 in parallel is given by 1 RT = 1 1 1 . +R +R R1 2 3 1

Create variables for the three resistors and store values in each, and then calculate the combined resistance. 8. The function sin calculates and returns the sine of an angle in radians. Use help elfun to nd the name of the function that returns the sine of an angle in degrees. Verify that calling this function and passing 90 degrees to it results in 1. 9. In the workspace type spy. This is another easter egg. Now back to work. 10. A vector can be represented by its rectangular coordinates x and y or by its polar coordinates r and . The relationship between them is given by the equations: x = r * cos() y = r * sin() Assign values for the polar coordinates to variables r and theta. Then, using these values, assign the corresponding rectangular coordinates to variables x and y. 11. Wind often makes the air feel even colder than it is. The Wind Chill Factor (WCF) measures how cold it feels with a given air temperature T (in degrees Fahrenheit) and wind speed (V, in miles per hour). One formula for the WCF is:

W CF = 35.7 + 0.6T 35.7(V 0.16 ) + 0.43T (V 0.16 ) Create variables for the temperature T and wind speed V, and then using this formula calculate the WCF. 12. In the workspace type life and follow the instructions of the new window. This is a quite sophisticated easter egg. 13. Store a number with a decimal place in a double variable (the default). Convert the variable to the type int32 and store the result in a new variable. 14.

Generate a random (a) real number in the range from 0 to 1

(b) real number in the range from 0 to 20 2

(c) real number in the range from 20 to 50 (d) integer in the range from 0 to 10 (e) integer in the range from 0 to 11 (f) integer in the range from 50 to 100 15. Get into a new Command Window, and type rand to get a random real number. Make a note of the number. Then, exit MATLAB and repeat this, again making a note of the random number; it should be the same as before. Finally, exit MATLAB and again get into a new Command Window. This time, change the seed before generating a random number; it should be dierent. 16. If you have time left, type helpbrowser and read about the built-in functions of MATLAB.