You are on page 1of 3

Prof.

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 file <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 file 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 find out the maximum number of characters that you can have in an identifier name under your version of MATLAB. 5. Explore the format command in more detail. Use help format to find 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

10. assign the corresponding rectangular coordinates to variables x and y. 9. Use help elfun to find the name of the function that returns the sine of an angle in degrees.43T (V 0.7(V 0.6T − 35. 14. Convert the variable to the type int32 and store the result in a new variable. and then using this formula calculate the WCF. 8. Then.Create variables for the three resistors and store values in each. 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. in miles per hour). One formula for the WCF is: ∗ W CF = 35. using these values. This is another easter egg.7 + 0. The function sin calculates and returns the sine of an angle in radians. Now back to work. In the workspace type life and follow the instructions of the new window. The Wind Chill Factor (WCF) measures how cold it feels with a given air temperature T (in degrees Fahrenheit) and wind speed (V. and then calculate the combined resistance. Wind often makes the air feel even colder than it is. This is a quite sophisticated easter egg. Store a number with a decimal place in a double variable (the default).16 ) + 0. A vector can be represented by its rectangular coordinates x and y or by its polar coordinates r and θ. In the workspace type spy. 13. 12. 11.16 ) Create variables for the temperature T and wind speed V. Verify that calling this function and passing 90 degrees to it results in 1. ∗ Generate a random (a) real number in the range from 0 to 1 (b) real number in the range from 0 to 20 2 .

exit MATLAB and again get into a new Command Window. If you have time left. 3 . it should be the same as before.(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. exit MATLAB and repeat this. Then. This time. again making a note of the random number. it should be different. Get into a new Command Window. and type rand to get a random real number. Make a note of the number. change the seed before generating a random number. Finally. type helpbrowser and read about the built-in functions of MATLAB. 16.