Presentation is loading. Please wait.

Presentation is loading. Please wait.

Numerical Functions & Tricks In today’s lesson we will look at: why we might want to use mathematical techniques some useful functions other mathematical.

Similar presentations


Presentation on theme: "Numerical Functions & Tricks In today’s lesson we will look at: why we might want to use mathematical techniques some useful functions other mathematical."— Presentation transcript:

1 Numerical Functions & Tricks In today’s lesson we will look at: why we might want to use mathematical techniques some useful functions other mathematical ideas

2 Computers are better at handling whole numbers (integers), and you can easily get rounding errors when working with long decimal numbers. You might need to write a program that performs a calculation – e.g. for a bank or insurance company You can use mathematical techniques for more interesting things, such as motion, or for cycling through a limited number of colours (like on the Spots theme for the ECOS web-site) Why Manipulate Numbers?

3 MOD: performs a division and gives you the remainder – e.g. 10 MOD 3 returns 1 MOD is useful if you want to cycle through a fixed number of options, e.g. dim c$(3) c$(1) = "Red" c$(2) = "White" c$(0) = "Blue" for n = 1 to 20 print n; " - "; c$(n MOD 3) next Useful Operations

4 Powers/Indices: to raise a number to a power, we use the ^ symbol (sometimes called a hat) For example, 4^3 would calculate 4 3 The sqr() function gives you the square root - e.g. sqr(16) returns 4 You can also use fractions like you do in GCSE Maths – e.g. 27^(2/3) returns 9 Useful Operations

5 abs(): gives you the absolute value of a number - i.e. without the sign. For example, abs(-1) would return 1 val(): gives you the numerical value of a string, e.g. val(“2.5”) would return the value 2.5. str$(): turns a number into a string, e.g. str(10) would would return a string containing “10”. Useful Functions

6 int() rounds a number down You must write a program or function to round in other ways, e.g. input "Give me a number: "; n input "How many decimal places? "; dp exp = 10^dp Print int(n*exp+0.5)/exp Rounding

7 You can change the sign of a number by multiplying by -1 You can use this idea to make things bounce – e.g. multiply their speed by -1 so that they go the other way, Computers are much better at working with whole numbers, so for things like money it is better to work in pence, and just divide by 100 when you want to display the answer Tricks & Tips

8 Boolean Operators – AND, OR, NOT Binary – representing numbers using only 0s and 1s Hexadecimal – used to describe colours Bitwise Boolean Operators: these take the Boolean Logical Operators and apply them to individual bits in the binary representation of numbers – this is how the binary flags page works. Further Reading


Download ppt "Numerical Functions & Tricks In today’s lesson we will look at: why we might want to use mathematical techniques some useful functions other mathematical."

Similar presentations


Ads by Google