# Exercise

Document Sample

```					                    Practical Exercise Sheet 1
Basic Arithmetic and Command Line Exercises

Exercise
All the following should be done in MATLAB .

1. Multiply 5 and 6.

2. Let us consider the compound interest program introduced in Lectures:
Execute the following statements in the Command Window:

(a) Put the number 1000 into variable balance
(b) Put the number 0.09 into variable rate
(c) Multiply the contents of rate by the contents of balance and put the answer
in interest
(d) Add the contents of balance to the contents of interest and put the answer in
balance
(e) Display (in the Command Window) the message given in single quotes.
(f) Display the contents of balance
(g) What values do variables balance, interest, and rate have at the end of the
program?

3. Give values to variables a and b on the command line, e.g. a = 3 and b = 5. Write
some statements to ﬁnd

(a) the sum
(b) the diﬀerence
(c) the quotient

of a and b respectively.

4. Enter the following numbers at the command prompt in scientiﬁc notation:

(a) 1.234 × 105 ,
(b) −8.765 × 10−4 ,
(c) 1015 ,
(d) −10−12 .

5. Use MATLAB to evaluate the following expressions

1
(a) 1 + 2 × 3
(b) 4/(2 × 2)
(c) (1 + 2)/4
(d) 1 + 2/4
1
(e)   2×3
2×3
(f) 2
(g) 1.5 × 10−4 + 2.5 × 10−2
(h) 1000 (1 + 0.15/12)6 0. What does this mean?
6. Try to avoid using unnecessary brackets in an expression. Can you spot the errors
in the following expression (test your corrected version with MATLAB ):

(2 (3+4)/(5*(6+1))^2

7. Find the volume of a cylinder of radius 5cm and height 10cm. Hint: type pi in
MATLAB .
8. Suppose a and b are deﬁned as follows:

a = [2 -1 5 0];
b = [3 2 -1 4];

Evaluate by hand the vector c in the following statements. Check your answers
with MATLAB
(a) c = a − b,
(b) c = 2 × a + ab (Be careful! )
(c) c = b/a
(d) c = b × 2 × a
9. Scientists often have to convert from one unit of measurement to another; this
can be tricky sometimes. You need to think carefully through the process. For
example, convert 5 acres to hectares, given that an acre is 4840 square yards, a
yard is 36 inches, an inch is 2.54cm and a hectare is 10 000m2 . The best approach
is to develop a formula to convert x acres to hectares. You can do this as follows:
one square yard = (36 × 2.54)2 cm2
so one acre = 4840 × (36 × 2.54)2 cm2
= 0.4047 × 108 cm2
= 0.4047 hectares
so x acres = 0.4047x hectares
Once you have found the formula (but not until you have found the formula),
MATLAB can do the best. Convert 5 acres to hectares and display the answer
on the Command Window.

2
10. Develop formulae for the following conversions, and use some MATLAB state-

(a) Convert 22 yards (an imperial cricket pitch) to meters
(b) One pound (weight) = 454 grams. Convert 75 kg to pounds
(c) Convert 49 meters/second
(terminal velocity for a falling person-shaped object) to km/hour
(d) One calorie = 4.184 joules. Convert 6.25 kilojoules to calories

Quitting MATLAB
Give the instruction quit or exit (or use the command window’s menu).

3

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 17 posted: 3/11/2011 language: English pages: 3