Download presentation
Presentation is loading. Please wait.
Published byEdward Cummings Modified over 9 years ago
1
Formal Computational Skills Week 1: Functions
2
Overview By the end you should: Be able to evaluate a function Know how to visualise a function Know what e 2 is Know what a linear equation is Be able to read summation and product notation These are basics needed in later lectures Will also do a little bit of logarithms and powers to re- familiarise you with maths and mathematical thinking
3
Functions of a single variable Usually: y = f(x)or: y(x) = f(x) Read as: “y is a function of x” Sometimes referred to as a mapping or transformation: f: x -> y Read as: “f takes/maps/transforms x into y” x is the input/argument/parameter/independent variable f takes x as an input and transforms it into the output y and is therefore known as the dependent variable) Implicitly assumed that y depends only on x (and constant values eg 2, speed of light etc)
4
Examples y = sin(x) y = cos(x) Last eg seems different as it is y = sum of functions of x. However all the above (sin, cos, log, e) are actually shorthand for (infinitely) long sums A lot of learning maths is learning this shorthand Means “identically equal to” ie defined to be the same y = 3x + 2 eg the function “if x is less than 3, y = 0, otherwise y = 1” is written:
5
Evaluating Functions Functions must be evaluated for values of x y(x) means y evaluated at x so y(3) means y evaluated at x=3. Eg to evaluate y(x) = x 2 + 3x + sin(x) at x=3 put 3 instead of x in the equation: y(3) = 3 2 + 3(3) + sin(3) = 9 + 9 + 0.05 = 18.05 In many cases, functions cannot be evaluated and must be approximated eg by truncation of an infinite sum. NB most computer evaluated functions are like this and to save time often use eg look-up tables which give y for values of x
6
Bracket Ambiguities Brackets can be ambiguous. Sometimes they mean multiply eg y(y+1) means y times (y+1) Sometimes indicate dependence of 1 variable on another eg y(x) (normally) means that y takes x as a (input) variable Can even be used in the same expression eg: y(x) = x(x + a) means y is a function of x and is equal to x times (x+a). However, could read as y times x equals x times (x+a) Knowing which is largely a matter of experience as it depends on the context. Normally do whatever makes ‘sense’
7
Visualising Functions Functions are visualised by plotting them as graphs where you can see the value of the output for every input By convention, independent variable along the horizontal (x- axis) and dependent along the vertical (y-axis) Plot of y = sin(4x) + 1.2
8
Plotting graphs Clearly cannot evaluate y for the infinitely many values of x so instead, idea is to evaluate y for a number of values of x: For a smoother plot use more x (and y) values Simple as we do this by computer (eg matlab) x =00.10.20.3 y=sin(4x)+1sin(0)+1=1sin(.4)+1=1.3sin(.8)+1=1.6sin(1.2)+1=1.8 and interpolate between them (here with straight lines) Plot each of the (x,y) pairs x (0, 1) x (0.1, 1.3) x x
9
Not just for visualisation: graphs can aid analysis since the line is the function and the function is the line Thus points satisfying y = 10x are ALL the points on this line and ONLY points on this line Why? y has been specified for EVERY x Eg suppose we are asked to solve y = 10x and y = e x ie we want points [(x,y) pairs] that satisfy both equations “satisfy” means “to make the equations true” so eg (x,y)=(1,10) or (2,20) satisfy y=10x
10
Similarly, all the points where y = e x are on this line points where the lines cross So if we draw both lines on the same graph: Are on both lines, and thus satisfy both equations In this way we graphically estimate the solution to the equations
11
This relates to question 1
12
Functions of several variables Functions can have many dependent variables and are written: z = f(x,y) z = x exp(-x 2 + -y 2 ) or (more often): y = f(x 1, x 2, …, x n ) Which reads as “y is a function of n variables x 1, x 2, …, x n ” Implicitly assumed that the variables are of the same type. Thus, in neural networks see: y = f(x 1, …, x n, w 1, …, w m ) Which reads (implicitly) as: “the output, y, is a function of n x- type variables (eg inputs) and m w-type variables (weights)”
13
In such cases, functions are often visualised as surfaces or landscapes eg The analogy only really holds for functions of 2 variables, but often used for higher dimensions (possibly misleadingly…) Plot of z = x exp(-x 2 + -y 2 )
14
Equation of a straight line The equation of a straight line is:y = mx + c Where m and c are constants. m is the gradient or slope, c is the intercept. y = 4x, m=4 m specifies how much y changes if we change x by 1. y = 1x =x, m=1 y = 2x, m=2 y = 0x = 0, m=0 y = -x, m=-1 If m = 0, y = constant, If m<0 y decreases as x increases.
15
c specifies where the line crosses (intercepts) the y-axis y = 2x + 2 y = 2x y = 2x - 3 If y= mx +c say equations are linear ONLY linear equations specify straight lines. c=- 3 c=0 c=2 Thus find c by evaluating y at x=0
16
Say an equation is linear if the highest power of the dependent variables is 1 (or less) Eg y = 2x 1 +4x 2 +1, or y = 6x 1 +x 3 -4x 8 but not y = 6x 1 +x 3 2 Linear Equations Equation is linear in x but non-linear in w If an equation is not linear it is said to be non-linear and it will be a curve. What about: y= w 1 2 x 1 +w 2 x 2 ? Linear equations of more variables specify planes or hyperplanes
17
Linear equations are important because they are mathematically simple This makes them easy to work with and to solve eg what is x when y = 3? In particular, they are predictable as everything stays the same. Thus, if we experiment locally to find properties we know what is happening globally Linear is easy: x=6But for non-linear can be many solutions: more complex
18
Summation and Product Notation Simply shorthand (again) for lazy mathematicians eg: Read as: “the sum for i = 1 to 4 of a i x i ”. Can think of it as a ‘for’ loop: sum = 0; for i = 1 to 5 do sum += a[i] x[i]; end; Often see In which case it is implicitly assumed that the sum is over ALL i or
19
Double summation helps to write out some terms: Product notation: same as summation but with multiplication eg
20
This relates to questions 2-4
21
Polynomials Polynomials are functions like: y = 2 + x + 3x 2 – 1.3x 4 So linear equations are polynomials In general they are functions which can be written as andRemember EVERY FUNCTION IS A POLYNOMIAL
22
Order of a Polynomial The order of the polynomial is the highest power of x that appears in it (Often most of the a i ’s are 0). Eg: y = 2 + x + 3x 2 – 1.3x 4 is 4 th order linear equations: z = 2x +3y – 6 are 1 st order The higher the order the more complex the function can be - ie the more complicated it is to explain to somebody - ie the more information you would need to tell them about it – directly related to the number of a i ’s you would have to tell someone so they could recreate the function exactly (sort of) Information Theory
23
1 st order: linear 0 th order: constant 2 nd order: quadratic When approximating or generalising, we ignore higher order terms as they often specify noise (NB if |x|<1, x i gets small for high i) high order
24
Powers Multiplication: 2 2 2 3 = (2 x 2) (2 x 2 x 2) = 2 x 2 x 2 x 2 x 2 = 2 5 Similarly: y 2 y 3 = (y x y) (y x y x y) = y 5 And: Division: And:
25
2 special cases: Powers of powers: Special case: x 1/2 ie anything to the power of 0 is 1 ie anything to a negative power is 1 over it to a positive power Similarly: So x 0.5 is ok but what about x 2.12 or even x ??? Actually something more complicated going on but won’t affect us
26
Exponential equations Exponential equations are equations like: y = 2 kx where k is a constant. If k>0 say y is exponentially increasing eg bacteria doubling: 1, 2, 4, 8, … Numbers get very big very quickly 2x2x 2x2x 3x3x Often see e x. e is simply a number, 2.7183 … to be precise (-ish) Why is it important? Because if you differentiate ex, it stays exactly the same. Means that it is easy to work with exex
27
If k<0 say y is exponentially decreasing eg radioactive decay. 1, ½, ¼, … Numbers decrease but approach 0 asymptotically (ie by smaller and smaller amounts and never quite reaching it) What about k=0?? e -0.5x e -0.25x The bigger the size (magnitude) of k (written as |k|), the quicker the increase or decrease
28
Logarithms Logs are basically the opposite of powers and are defined as: Means implies and is implied by or analogously if and only if So: log 10 100 = 2 since 10 2 = 100 However, the only bases (in log b the base is b) used are 10 and e (and sometimes 2). All others can be got simply from these log 10 is almost always shorthanded to log and log e is shorthened to ln (as it is the natural logarithm). The (important) exceptions are most programming languages where log(x) normally returns ln(x)
29
Some rules of logs (won’t prove them but you can if you like): 1. By definition logs undo powers and vice versa so: ln(e cos(x) ) = cos(x) Same way as multiplication undoes division (notion of function inverses) 2. log(xy) = log(x) + log(y) eg if: Used in probability as easier to work with a sum than a product
30
Why are they used? How long to get 768 bacteria if populatioon is doubling every second? Must solve: n = 2 t = 768 ??? Do log 2 768 = n = 9.59 s Also if you plot the number of bacteria (n) from an experiment against time, numbers get very big very quickly: hard to plot the graph and hard to calculate errors. But if you plot log(n) against t, if the relationship is exponential, graph is a straight line and the gradient determines k
31
This relates to questions 5-7
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.