Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Lecture 3: More on functions

This lecture includes

Convexity

Linear functions

Polynomials

Approximation by polynomials
Before we start...

Tutorials (applied classes) start this week


Also use your tutorials to ask questions!
Convex functions

A function is convex if, for any two points in its plot, the
straight line between both points is entirely above (or touch-
ing) the plot of the function.

Example 1

4 4

3 3

2 2

1 1

-2 -1 1 2 -2 -1 1 2

2 x
(a) f (x) = 2x (b) f (x) = 2

Example 2 A function with a straight line graph is convex.


Concave functions

A function is concave if, for any two points in its plot, the
straight line between both points is entirely below (or touch-
ing) the plot of the function.

Example

0.5 1.0 1.5 2.0

-1

-2

-3
Side note

The formal definition for convexity is the following:

f is convex if, for all x1 , x2 in its domain and a ∈ [0, 1],

f (ax1 + (1 − a)x2 ) ≤ af (x1 ) + (1 − a)f (x2 ).

f is concave if, for all x1 , x2 in its domain and a ∈ [0, 1],

f (ax1 + (1 − a)x2 ) ≥ af (x1 ) + (1 − a)f (x2 ).

This side note is only meant to provide more details to people


interested in the topic. You do not have to remember the
definitions above!
Predicting data with functions

250
4

200
3

150
y
y

100
1

50
5 10 15 20 5 10 15 20

x x
16
14

5.0
12

4.5
10
y

y
8

4.0
6

3.5
4

10 15 20 25 10 15 20 25 30 35 40

x x
Linear functions

A linear function is a function f : R → R with

f (x) = mx + b

where m and b are real numbers.


m is called the slope of the function

Examples
f (x) = 21 x − 1
f (x) = −2x + 3
f (x) = 1
Geometric interpretation of m and b
f (x) = mx + b
For each ’step’ to the right take m steps up (if m ≥ 0)
If m is negative, say m = −q, take q steps down instead
b is the y -coordinate where f intersects with the y -axis.

f (x) = 12 x − 1
Fitting a linear function through two data points

5
4
3
y

2
1

5 10 15 20

It is often useful to find a linear function that approximates


the data ’best’ (in the sense of mean square errors)
For today, we only discuss how to fit a linear function through
two data points
Example
Finding a linear function passing through (1, 3) and (2, 4):

Option 1. ’By hand’ — substitute directly into formula


Example
Finding a linear function passing through (1, 3) and (2, 4):

Option 1. ’By hand’ — substitute directly into formula


A linear function is of the form f (x) = mx + b.
Passing through the points means 3 = f (1) and 4 = f (2), i.e.

3 = m × 1 + b,
4 = m × 2 + b.

We will discuss later in the course how to solve such equations


in general. Here, just note that b = 3 − m by the first
equation and b = 4 − 2m by the second. This only works if

4 − 2m = 3 − m

and thus m = 1. Substituting m = 1 in either of the


equations above yields b = 2.
Finding a linear function passing through (1, 3) and (2, 4):

Option 2. Using the following way to derive the slope:

Let (x1 , y1 ) and (x2 , y2 ) be two points with x1 6= x2 . The


slope of the linear function passing through both points is
y2 − y1
.
x2 − x1
Finding a linear function passing through (1, 3) and (2, 4):

Option 2. Using the following way to derive the slope:

Let (x1 , y1 ) and (x2 , y2 ) be two points with x1 6= x2 . The


slope of the linear function passing through both points is
y2 − y1
.
x2 − x1

To find m: the formula yields


4−3
m= = 1.
2−1
To find b: plugging the first point into y = mx + b yields

3=m×1+b =1+b

(as we found m = 1). Hence b = 2.


Our final formula for the linear function: f (x) = x + 2.
Properties of linear functions

Let f be a linear function (i.e. f (x) = mx + b).

Zeroes?

Bijection?

Convex/Concave?
Properties of linear functions

Let f be a linear function (i.e. f (x) = mx + b).

Zeroes? If m 6= 0, f has exactly one zero:


b
mx + b = 0 if and only if x = − .
m
If m = 0, we either have no zeroes (if b 6= 0) or every real x is a
zero (if b = 0).

Bijection?

Convex/Concave?
Properties of linear functions

Let f be a linear function (i.e. f (x) = mx + b).

Zeroes? If m 6= 0, f has exactly one zero:


b
mx + b = 0 if and only if x = − .
m
If m = 0, we either have no zeroes (if b 6= 0) or every real x is a
zero (if b = 0).

Bijection? If m 6= 0, f is bijective (find an inverse function!). If


m = 0 the function is not injective and the image f (X ) is {b}.

Convex/Concave?
Properties of linear functions

Let f be a linear function (i.e. f (x) = mx + b).

Zeroes? If m 6= 0, f has exactly one zero:


b
mx + b = 0 if and only if x = − .
m
If m = 0, we either have no zeroes (if b 6= 0) or every real x is a
zero (if b = 0).

Bijection? If m 6= 0, f is bijective (find an inverse function!). If


m = 0 the function is not injective and the image f (X ) is {b}.

Convex/Concave? Linear function are both convex and concave


Example of application: market of watermelons
n − th year: price Pn , supply Qn .
Experience: When Qn increases, Pn decreases. When Pn
increases, Qn+1 increases.
Example of application: market of watermelons
n − th year: price Pn , supply Qn .
Experience: When Qn increases, Pn decreases. When Pn
increases, Qn+1 increases.

Mathematical model:
(
Pn = a − bQn ,
Qn+1 = c + dPn .

where a, b, c, d are parameters, to be determined.


Example of application: market of watermelons
n − th year: price Pn , supply Qn .
Experience: When Qn increases, Pn decreases. When Pn
increases, Qn+1 increases.

Mathematical model:
(
Pn = a − bQn ,
Qn+1 = c + dPn .

where a, b, c, d are parameters, to be determined.


Fit the model with the samples
Year 2000 2001 2002
Data in Statistics department: P P1 P2 ??
Q Q1 Q2 Q3
Find a, b, c, d, Solve for Pn . Predict the behaviour of Pn when
n → ∞.
Polynomial functions
A polynomial function of degree n is a function with

f (x) = an x n + an−1 x n−1 + . . . + a1 x + a0

where a0 , . . . , an are real numbers and an 6= 0.

Examples
1
f (x) = x 3 + 2x 2 − x + 2 is a polynomial function of degree 3
f (x) = −0.3 is a polynomial function of degree 0
f (x) = 21 (x − 2)2 + 3 is a polynomial function of degree 2
Linear functions (with m 6= 0) are polynomials of degree 1
Sigma notation. Recall that we can also write
n
X
f (x) = ai x i .
i=0
Approximation with polynomials

In Theory
Suppose we are given n + 1 data points (x0 , y0 ), . . . , (xn , yn ).
We can always try to find a polynomial of degree n that
passes through all data points
This requires solving a system of n + 1 linear equations. We
will learn how to do that in a couple of weeks

In Practice
For very large data sets (large n) this might be unnecessarily
complicated and inefficient
We might permit some “noise” into the model – find simple
functions that are a reasonable approximation of data
How about these data points?

250
200
150
y

100
50

5 10 15 20

x
How about these data points?

250
200
150
y

100
50

5 10 15 20

Data does not look like a linear function


Might be quadratic?
600
500

20
400

15
y^(1/2)
300
y

200

10
100

5
0

5 10 15 20 25 30 35 5 10 15 20 25 30 35

x x

Finding the ’best’ approximation with quadratic functions is


possible but complicated
For now only try to find a quadratic function f (x) = ax 2 + c
through two of the data points
Exercise
Find real numbers a and c such that the function f (x) =
ax 2 + c passes through the points (2, 4) and (4, 10)
Exercise
Find real numbers a and c such that the function f (x) =
ax 2 + c passes through the points (2, 4) and (4, 10)

We want f (2) = 4 and f (4) = 10, i.e.

a × 22 + c = 4,
a × 42 + c = 10

Hence c = 4 − 4a and c = 10 − 16a. The only way this works is if

4 − 4a = 10 − 16a.

Thus a = 1/2. With c = 4 − 4a we get c = 2.

The answer is: f (x) = 12 x 2 + 2.

You might also like