* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Slides 4 per page
Survey
Document related concepts
Foundations of mathematics wikipedia , lookup
Infinitesimal wikipedia , lookup
Georg Cantor's first set theory article wikipedia , lookup
Law of large numbers wikipedia , lookup
Location arithmetic wikipedia , lookup
Positional notation wikipedia , lookup
Mathematics of radio engineering wikipedia , lookup
Hyperreal number wikipedia , lookup
Proofs of Fermat's little theorem wikipedia , lookup
Large numbers wikipedia , lookup
Real number wikipedia , lookup
Transcript
Basic Curriculum • Basic Maths • • Maths for Computer Graphics Trigonometry (lines, triangles, circles) 3D Maths • • http://nccastaff.bournemouth.ac.uk/jmacey/MathsForCG/index.html Vectors, Matrices, Affine Transforms How Animation Systems work • • • The Computer Image, The Animation Pipeline (how XSI, Maya, Houdini, Shake etc really work) Some Basic Computer Principles, How the computer Actually works Rendering • • How a renderer actually produces and image, Lighting Models, Shading Models. And a whole lot more besides. 2 Tuesday, 13 October 2009 Tuesday, 13 October 2009 Numbers Using Python as a Calculator • To demonstrate some of the principles of Maths for CG we will be using the python console as a calculator • This will allow you to get a feel for how computers process numbers and is advantageous when beginning to create scripts. • A number is an abstract entity used originally to describe quantity. • • • • i.e. 80 Students etc The most familiar numbers are the natural numbers {0, 1, 2, ...} or {1, 2, 3, ...}, used for counting, and denoted by N or N This set is infinite but countable by definition. To be unambiguous about whether zero is included or not, sometimes an index "0" is added in the former case, and a superscript "*" is added in the latter case: No = {0, 1, 2, ...}N ∗ = {1, 2, ....} Tuesday, 13 October 2009 Tuesday, 13 October 2009 Integers Integers in Computers • The integers consist of the positive natural numbers (1, 2, 3, -), their negatives (-1, -2, -3, ...) and the number zero. • The set of all integers is usually denoted in mathematics by Z or , Z which stands for Zahlen (German for "numbers"). • They are also known as the whole numbers, although that term is also used to refer only to the positive integers (with or without zero). • • Most programming languages have an integer data type They are usually used for counting and index values 1 Tuesday, 13 October 2009 2 3 4 5 6 7 8 9 10 11 An integer is usually in the range -32,768 to 32,767 . //C++ / C int a=1; // Maya Mel int $a=1 // Python a=1 Tuesday, 13 October 2009 Rational Numbers Number Lines !"#$#% Tuesday, 13 October 2009 '+ '* ') '( & ( ) * • + • The number line is a diagram that helps visualise numbers and their relationships to each other. • The numbers corresponding to the points on the line are called the co-ordinates of the points. • The distance between to consecutive integers is called a unit and is the same for any two consecutive integers. • The point with co-ordinate 0 is called the origin. • • In mathematics, a rational number (or informally fraction) is a ratio or quotient of two integers a It is usually written as the vulgar fraction b or a/b, where b is not zero. Each rational number can be written in infinitely many forms, for example 3 2 1 = = 6 4 2 Tuesday, 13 October 2009 Real Numbers "('& "& • • "% "$ "# #'$ ! !$ # Real Numbers " $ % & For every rational number there is a point on the number line 1 For example the number 2 corresponds to a point halfway between 0 and 1 on the number line. • • and − 4 corresponds to a point one and one quarter units to the left of 0. • The set of points that corresponds to all points on a number line are called the set of Real Numbers. 5 Since there is a correspondence between the numbers and points on the number line the points are often referred to as numbers Tuesday, 13 October 2009 • Real numbers may be rational or irrational; algebraic or transcendental; and positive, negative, or zero. • • Real numbers measure continuous quantities. • Measurements in the physical sciences are almost always conceived as approximations to real numbers. Tuesday, 13 October 2009 Real Numbers • Tuesday, 13 October 2009 They may in theory be expressed by decimal fractions that have an infinite sequence of digits to the right of the decimal point; floating point data types Computers can only approximate most real numbers with rational numbers; these approximations are known as floating point numbers or fixed-point numbers. • Computer algebra systems are able to treat some real numbers exactly by storing an algebraic description (such as "sqrt(2)") rather than their decimal approximation. • Mathematicians use the symbol R or alternatively R to represent these numbers Tuesday, 13 October 2009 • • • Real numbers are represented using floating point data types. • In most languages we have two sizes for our real data types. Most computer systems have several ways of representing them The different representations are dependent upon the number of bit the operating system use (32 vs 64) Symbols real data types 1 2 3 4 5 6 7 8 9 10 11 • Mathematicians use all sorts of symbols to substitute for natural language expressions. • Here are some examples // A float is usually in the range +/- 3.4 e +/- 30 (˜7 Digits) // C++ / C float a=2.5; < > ≤ ≥ ≈ ≡ % = // Mel float $a=2.5; // Python a=2.5 Tuesday, 13 October 2009 1 2 3 4 5 6 7 8 9 10 11 12 # less than a<b # greater than a>b # less than or equal to a<=b # greater than or equal to a>=b # Not equal a!=b # equality a==b Tuesday, 13 October 2009 Boolean Values • Boolean values are used to hold truth values. • Typically in a computer these values are stored as • 1 == true • 0 == false • Some modern languages actually use the values true and false to make the code more readable. • We use boolean values to store the results of Comparing Floating point values 1 2 3 4 5 6 7 8 9 10 11 #!/usr/bin/python 1 2 3 4 5 6 False False True True False True a=1 b=1 print print print print print print a<b a>b a<=b a>=b a!=b a==b • floating point data values are not accurate and comparing them may lead to strange problems (especially in Python) • Consider the following python example 1 2 3 4 5 6 7 8 9 10 11 12 13 comparisons Tuesday, 13 October 2009 less than greater than less than or equal to greater than or equal to approximately equal equivalent to not equal to Tuesday, 13 October 2009 #!/usr/bin/python # declare a to be equal to 0.2+0.1 (should be 0.3) a=(0.2+0.1) # declare b as 0.3 directly b=0.3 print "testing equality" if( a == b) : print a,b," are the same" else : print a,b," are different" Irrational Numbers Better Comparison • • Usually with floating point values we compare to see if we are close To do this we use an error margin (usually called epsilon) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #!/usr/bin/python def FCompare(a,b) : epsilon = 0.0000000000001 return ( ((a)-epsilon)<(b) and ((a)+epsilon)>(b) ) # declare a to be equal to 0.2+0.1 (should be 0.3) a=(0.2+0.1) # declare b as 0.3 directly b=0.3 print "testing equality" if( FCompare(a,b)) : print a,b," are the same" else : print a,b," are different" Tuesday, 13 October 2009 All rational numbers are real numbers, but there are points on the number line that do not correspond to rational numbers. • Those real numbers that are not rational are called irrational numbers • • • An irrational numbers cannot be written as a ratio of integers. √ It can be show that numbers such as 2 and π are irrational Irrational numbers are not as easy to represent as rational numbers Tuesday, 13 October 2009 Irrational Numbers II • • Usually they are represented using symbols such √ √ as 2, 3 and π When we perform computations with irrational numbers we use rational approximations for them • For example : √ • 2 ≈ 1.414 and π ≈ 3.141 √ • Note that not all square roots are Irrational for example 9 = 3 Absolute Value • The absolute value of a number is the numbers distance from 0 (origin) on the number line. • For example the numbers 5 and -5 are both five units away from 0 on the number line. • • So the absolute value of both these number is 5 We write |a| for the absolute value so |5| = 5 and |−5| = 5 because 3 × 3 = 9 Tuesday, 13 October 2009 • • Tuesday, 13 October 2009 The notation |a| represents distance, and distance is never negative so |a| is greater than or equal to zero for any real number abs() in python 1 2 3 4 5 1 2 3 4 5 6 7 8 9 10 11 12 13 from math import * a=5 b=-5 fa=5.02234 fb=-5.02234 print print print print "abs(a) = ",abs(a) "abs(b) = ",abs(b) "abs(fa) = ",abs(fa) "abs(fb) = ",abs(fb) [jmacey@neuromancer:Lecture1]$./absolute.py abs(a) = 5 abs(b) = 5 abs(fa) = 5.02234 abs(fb) = 5.02234 Tuesday, 13 October 2009 • Two numbers that are located on opposite sides of zero and have the same absolute value are called opposites • • • The number 5 and -5 are opposite to each other. The symbol "-" is used to indicate opposite as well as negative. When the negative sign is used before a number it should be read as "negative" Tuesday, 13 October 2009 • • • Opposites When it is used in front of parentheses or a variable it should be read as "opposite" -(5) = -5 means the "opposite" of 5 is "negative" 5 In general -a means "the opposite of a" • • • If a is positive, -a is negative. If a is negative, -a is positive. opposite.py 1 2 3 4 5 6 7 8 9 10 11 12 13 #!/usr/bin/python from math import * a=5 b=0.234 c=-234 d=-0.4345 print print print print Using this we can give a symbolic definition of absolute value |a| = Tuesday, 13 October 2009 Opposites #!/usr/bin/python a −a if a is positive or zero if a is negative Tuesday, 13 October 2009 "-a "-b "-c "-d = = = = ",-a ",-b ",-c ",-d negate.py 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #!/usr/bin/python from math import * a=5 print print print print print print print print print print "-a = ",-a "--a = ",--a "---a = ",---a "----a = ",----a "-----a = ",-----a "------a = ",------a "-------a = ",-------a "--------a = ",--------a "---------a = ",---------a "----------a = ",----------a • Arithmetic Expressions The result of writing numbers in a meaningful combination with the arithmetic operations is usually called and arithmetic expression or expression • For example • The parentheses (or brackets) are used as grouping symbols and indicate which operation to perform first • Because of the parentheses these expressions have different values (3 + 2) × 5 and 3 + (2 × 5) arithmetic.py 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #!/usr/bin/python from math import * a=3 b=2 c=5 print "Using Numbers" print "(3+2) * 5 =",(3+2)*5 print "3+(2*5) = ",3+(2*5) 1 2 3 4 5 6 7 [jmacey@neuromancer:Lecture1]$./arithmetic.py Using Numbers (3+2) * 5 = 25 3+(2*5) = 13 Using variables (a+b)*c = 25 a+(b*c) = 13 print "Using variables " print "(a+b)*c = ",(a+b)*5 print "a+(b*c) = ",a+(b*c) (3 + 2) × 5 = 5 × 5 = 25 3 + (2 × 5) = 3 + 10 = 13 Tuesday, 13 October 2009 Tuesday, 13 October 2009 Exponential Expressions • • Exponential Expressions An arithmetic expression with repeated multiplication can be written by using exponents For example • • 2 × 2 × 2 = 23 and 5 × 5 = 52 • In general an expression of the form an is called an exponential expression and is defined as follows For any counting number n, If the exponent is 1, it is usually omitted e.g. 91 = 9 an = a × a × a × . . . × a ! "# $ n factors we call a the base and n the exponent Tuesday, 13 October 2009 The expression an is read "a to the nth power" Tuesday, 13 October 2009 power.py 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 #!/usr/bin/python "Powers" "3 raised to the power of 2 = 3*3 =",pow(3,2) "5 raised to the power of 5 is ",pow(5,5) "9 raised to the power of 1 is ",pow(9,1) print "Floating Point powers" print "2 raised to the power of 1.5 is ",pow(2,1.5) [jmacey@neuromancer:Lecture1]$./power.py Powers 3 raised to the power of 2 = 3*3 = 9.0 5 raised to the power of 5 is 3125.0 9 raised to the power of 1 is 9.0 Floating Point powers 2 raised to the power of 1.5 is 2.82842712475 Tuesday, 13 October 2009 When we evaluate expressions, operations within grouping symbols are always performed first • For example • To make expressions look simpler we sometimes omit some or all of the parentheses • • To do this we must agree in which order the operation are always carried out (3 + 2) × 5 = (5) × 5 = 25 and (2 × 3)2 = 62 = 36 We do multiplication before addition and exponential expressions before multiplication. 2 3 + 2 × 5 = 3 + 10 = 13 and 2 × 3 = 2 × 9 = 18 Tuesday, 13 October 2009 Order of Operations • If no grouping symbols are present, evaluate expressions in the following order: 1. Evaluate each exponential expression (in order from left to right). 2. Perform multiplication and division (in order from left to right). 3. Perform addition and subtraction (in order from left to right). • Tuesday, 13 October 2009 • from math import * print print print print Order of Operations For operations within grouping symbols, use the above order within the grouping symbols. Tuesday, 13 October 2009 Algebraic Expressions • Since variables (or letters) are used to represent numbers, we can use variables in arithmetic expressions. • The result of combining numbers and variables with the ordinary operations of arithmetic is called an algebraic expression • For example x + 2, πr2 , b2 − 4ac, and a−b c−d • Expressions are often named by the last operation to be performed in the expression. • For example the expression x + 2 is a sum because the only operation in the expression is addition Translating Algebraic Expressions Algebraic Expressions II • The expression a − bc is referred to as a difference because subtraction is the last operation to be performed • The expression 3(x − 4) is a product is a quotient • The expression • The expression (a + b) is a square because the addition is performed 3 x−4 • • Algebra is useful because it can be used to solve problems. • Consider the following examples of verbal expressions and their corresponding algebraic expressions Since problems are often communicated verbally, we must be able to translate verbal expressions into algebraic expressions and translate algebraic expression into verbal expressions 2 before the square is found Verbal Expression Algebraic Expression The sum of 5x and 3 The product of 5 and x + 3 5x + 3 5(x + 3) The The The The Tuesday, 13 October 2009 Tuesday, 13 October 2009 8+ 8+x 3 x 3 or (8 + 3)/3 or (8 + x) ÷ 3 3 − x2 (3 − x)2 Tuesday, 13 October 2009 algebra.py 1 2 3 4 5 6 7 8 9 10 11 12 13 sum of 8 and x3 quotient of 8 + x and 3 difference of 3 and x2 square of 3 − x • #!/usr/bin/python • from math import * "5x+3 = ",5*x+3 "5(x+3) = ",5*(x+3) "8 + x/3 = ",8+(x/3) " (8+x) / 3 = ",(8+x)/3 "3-xˆ2 = ",3-(x*x) "(3-x)ˆ2 = ",(3-x)*(3-x) The value of an algebraic expression depends on the values given to the variables. For example, the value of x − 2y where x = −2 and y = −3 is found by replacing x and y by − 2 and − 3 respectively print "Enter a value for x" x=float(raw_input(">")) print print print print print print Evaluating Algebraic Expressions x − 2y = −2 − 2(−3) = −2 − (−6) = 4 If x = 1 and y = 2, the value of x − 2y is found by replacing x by 1 and y by 2 x − 2y = 1 − 2(2) = 1 − 4 = −3 Tuesday, 13 October 2009 Expression.py 1 2 3 4 5 6 7 8 9 10 Equations • • #!/usr/bin/python from math import * print "Enter a value for x" x=float(raw_input(">")) print "Enter a value for y" y=float(raw_input(">")) • • print "x-2y = ",x-2*y An equation is a statement of equality of two expressions For example 11 − 5 = 6 , x + 3 = 9 , 2x + 5 = 13 and x are all equations. x −4=1 2 In an equation involving a variable any number that gives a true statement when we replace the variable with a number is said to satisfy the equation and is called a solution or root to the equation For example in the equation 2x + 5 = 13 the solution for x is x = 4 as (2 × 4) + 5 = 13 Tuesday, 13 October 2009 Tuesday, 13 October 2009 The Commutative Properties Properties of the Real Numbers • • • • • • There are a number of different properties associated with numbers They are used in arithmetic. In Algebra we must understand these to allow us to manipulate equations We get the same results whether we evaluate 3 + 5 or 5 + 3 This is an example of the commutative property of addition The fact that 4 × 6 and 6 × 4 show that multiplication is commutative. In General : For any real numbers a and b a + b = b + a and ab = ba Tuesday, 13 October 2009 Tuesday, 13 October 2009 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Commutative.py #!/usr/bin/python The Associative Properties from math import * print "Enter a value for x" x=float(raw_input(">")) print "Enter a value for y" y=float(raw_input(">")) print "Multiplication is Commutative " print "x*y =",x*y print "y*x =",y*x print "y-x = ",y-x print "x-y = ",x-y Consider the computation 2+3+6 using the order of operations we add 2 and 3 to get 5 and then add 5 and 6 to get 11 • If we reverse the order we get the same result so (2 + 3) + 6 = 2 + (3 + 6) print "Addition is Commutative" print "x+y = ",x+y print "y+x = ",y+x print "Division and Subtraction are not" • •We also have an associative property of multiplication. (2 × 3) × 4 = 6 × 4 = 24 or 2 × (3 × 4) = 2 × 12 = 24 So For any Real Numbers a, b and c print "y/x =",y/x print "x/y =",x/y (a + b) + c = a + (b + c) and (ab)c = a(bc) Tuesday, 13 October 2009 Tuesday, 13 October 2009 Associative.py 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Tuesday, 13 October 2009 The Distributive Property • #!/usr/bin/python from math import * print "Enter a value for a" a=float(raw_input(">")) print "Enter a value for b" b=float(raw_input(">")) print "Enter a value for c" c=float(raw_input(">")) Example : 3(4 + 5) = 3 × 9 = 27 or 3 × 4 + 3 × 5 = 12 + 15 = 27 • We say the multiplication by 3 is distributed over the addition. Distributive Property So For any Real Numbers a, b and c print "Addative Association " print "(a+b)+c =",(a+b)+c print "a+(b+c) =",a+(b+c) a(b + c) = ab + ac and a(b − c) = ab − ac print "Multaplicative Association" print "(ab)c = ",(a*b)*c print "a(bc) = ",a*(b*c) Tuesday, 13 October 2009 Distributive.py 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 The identity properties • • • • #!/usr/bin/python from math import * print "Enter a value for a" a=float(raw_input(">")) print "Enter a value for b" b=float(raw_input(">")) print "Enter a value for c" c=float(raw_input(">")) The numbers 0 and 1 have special properties. Multiplication of a number by 1 does not change the number Addition of 0 to a number does not change the number. That is why 1 is called the multiplicative identity and 0 is called the additive identity • • print "Distributive property " print "a(b+c) =",a*(b+c) print "ab+ac =",(a*b)+(a*c) Identity Properties For any real number a a × 1 = 1 × a = a and a + 0 = 0 + a = a print "a(b-c) =",a*(b-c) print "ab-ac =",(a*b)-(a*c) Tuesday, 13 October 2009 Tuesday, 13 October 2009 The Inverse Properties • This is written 1 1 such that a × = 1 a a Inverse Properties For any real number a there is a number -a such that a + (−a) = 0 1 For any nonzero real number a there is a number such that a a× Tuesday, 13 October 2009 Identity.py Every non-zero real number a also has a multiplicative inverse or reciprocal 1 =1 a 1 2 3 4 5 6 7 8 9 10 11 Tuesday, 13 October 2009 #!/usr/bin/python from math import * print "Enter a value for a" a=float(raw_input(">")) print print print print "Inverse property" "a+-a =",a+-a "Reciprocal of a (1/a) = ",1/a "a * 1/a = ",a*(1/a) • Properties of Integers The following table lists some of the basic properties of addition and multiplication for any integers a, b and c. closure associativity commutativity identity element inverse element distributivity Tuesday, 13 October 2009 addition Multiplication a + b is an integer a × b is an integer a + (b + c) = (a + b) + c a+b=b+a a+0=a a × (b × c) = (a × b) × c a×b=b×a a×1=a a + (−a) = 0 a × (b + c) = (a × b) + (a × c) Tuesday, 13 October 2009 References • Elementary and Intermediate Algebra, Mark Dugopolski McGraw Hill 1st Ed 2002 • • Engineering Mathematics, K. A. Stroud, Macmillan 3rd Edition 1987 • • • • • http://www.cplusplus.com/doc/tutorial/variables.html Collins Dictionary of Mathematics E. Borowski & J. M. Borwein Harper Collins 1989 http://en.wikipedia.org/wiki/Number http://en.wikipedia.org/wiki/Rational_number http://en.wikipedia.org/wiki/Real_numbers http://en.wikipedia.org/wiki/Floating-point_number