Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs...

23
120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 f(x) = e x at point c = 0. • Taylor‘s theorem: • Let • Hence,

Transcript of Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs...

Page 1: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 34

Visualization and Computer Graphics LabJacobs University

Example 2• f(x) = ex at point c = 0.• Taylor‘s theorem:

• Let

• Hence,

Page 2: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 35

Visualization and Computer Graphics LabJacobs University

Example 3

• Polynomial function at c=2.

• As the Taylor series in finite, the error term is 0 from some n on.

• Hence, the Taylor series represents the function.

Page 3: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 36

Visualization and Computer Graphics LabJacobs University

Example 4• f(x) = ln (1+x) at point c=0• f‘(x) = (1+x)-1

• f“(x) = -(1+x)-2

• f(k)(x) = (-1)k-1 (k-1)! (1+x)-k

• f(k)(0) = (-1)k-1 (k-1)!

Page 4: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 37

Visualization and Computer Graphics LabJacobs University

Example 4

• The Taylor series represents the function, if .• For other values of x, the error term may not converge

to 0.• Hence, for x > 1, we cannot use the Taylor series.

• Conclusion: We have to compute the so-called range of convergence before we apply Taylor expansion.

Page 5: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 38

Visualization and Computer Graphics LabJacobs University

Putting it into practice

• Use Taylor series to approximate function values.• Example 1: cos (0.1)• Actual value:• Taylor series at c=0:• Approximate values for cos (0.1) using truncated

Taylor series:

• Conclusion: We can quickly get good approximations.

Page 6: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 39

Visualization and Computer Graphics LabJacobs University

Speed of convergence

• We have observed that the Taylor expansion does nothave to converge to the actual solution.

• Question: If it does converge, how fast does itconverge?

• In practice: How many terms of the truncated Taylor series do we need for a good approximation?

Page 7: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 40

Visualization and Computer Graphics LabJacobs University

Observation• Compute ln (2):• First solution: Determine Taylor series for ln (1+x) at

c=0 and evaluate Taylor series for x=1.

Truncating after 8 terms delivers ln (2) ≈ 0.63452.• Second solution: Determine Taylor series for

at c=0 and evaluate Taylor series for x=1/3.

Truncating after 4 terms delivers ln (2) ≈ 0.69313.• The actual value is 0.69315.• The second solution converges much faster.

Page 8: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 41

Visualization and Computer Graphics LabJacobs University

Proximity of x to c

• The closer x is to c, the higher the accuracy of ourapproximation.

• Note that this error is in addition to the truncationerror.

Page 9: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 42

Visualization and Computer Graphics LabJacobs University

Taylor‘s theorem for f(x+h)

• Let .• Then, we get for that

with

truncatedTaylor series

error term

Page 10: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 43

Visualization and Computer Graphics LabJacobs University

Remarks

• This second theorem follows directly from the firstone for c = x+h.

• If h->0, the error term converges to 0 with at least the speed of hn+1, if the (n+1)-st derivative is boundedon the interval [x,x+h]. We write error term = O(hn+1).The O-notation means (there exists a C such that)

In our case, C > .

Page 11: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 44

Visualization and Computer Graphics LabJacobs University

Example• Evaluation of interest:• Use f(z) = ln (z) and expand at e. • Derivatives:

• Expansion:

• Range of convergence: sufficient

Page 12: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 45

Visualization and Computer Graphics LabJacobs University

Summary: Taylor series approximation

• Given problem: evaluate f(x) with error bound e.• Known: f(c) for c close to x.• Requirement: for .• Check: Taylor series represents function f on [a,b].• Estimate maximum error when computing f(x) using a

truncated Taylor series with n terms.• Choose n such that the estimated maximum error is

smaller than error bound e.• Evaluate the truncated Taylor series with n terms to

approximate f(x).

Page 13: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 46

Visualization and Computer Graphics LabJacobs University

Generalization: Numerical approach

• Given: “hard“ problem.• Solution: Find an algorithmic approach to solve the

problem approximately.• Caveat: Check the limitations/constraints of the

applicability of the approach.• Approximation error: Compare the maximum error to

the error threshold determined by the application.• Convergence: Numerical methods often improve when

executing more computations. Does the approximationconverge towards the actual solution? I.e., does theerror go to 0?

• Convergence rate: How fast does the error go to 0?

Page 14: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 47

Visualization and Computer Graphics LabJacobs University

Goals revisited

In this course, we will:• Discuss algorithmic approaches to solve standard

mathematical problems with applications in engineering and science.

• Discuss the approaches with respect to theirapplicability (constraints, convergence).

• Discuss the approaches with respect to thepracticability (approximation error, convergencerate).

Page 15: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 48

Visualization and Computer Graphics LabJacobs University

1.2 Number Representations

Page 16: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 49

Visualization and Computer Graphics LabJacobs University

Definition

• Let b є N\{1}.• Every number x є N0 can be written in a unique

representation with respect to base b by

with ai є N0 and ai < b.

Page 17: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 50

Visualization and Computer Graphics LabJacobs University

b=10• Base 10:

• Notation:

• Fractions:

• Real numbers:

Page 18: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 51

Visualization and Computer Graphics LabJacobs University

Infinite representations

• For irrational numbers (such as e or π) an infinite number of coefficients bi is required.

• But: not every infinite representation impliesirrationality. Counter-example: 1/3.

Page 19: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 52

Visualization and Computer Graphics LabJacobs University

Base representations in computers

• Computer systems are using– base 2 (binary)– base 8 (octal)– base 16 (hexadecimal)

Page 20: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 53

Visualization and Computer Graphics LabJacobs University

Simple base representations

• A number with a simple base representation withrespect to one base may have a complicated baserepresentation (many coefficients, maybe eveninfinite) with respect to another base.

Page 21: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 54

Visualization and Computer Graphics LabJacobs University

Base conversion

• How do we get from one base representation to another?

• In particular, how can we switch between bases 2, 8, 16, and 10?

Page 22: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 55

Visualization and Computer Graphics LabJacobs University

Conversion b->10

• (an an-1 … a0)b = an bn + an-1 bn-1 + … a0 b0

• Then, just do the math …• Example: (42)8 = 4x81 + 2x80 = (34)10

Page 23: Example 2 · 120202: ESM4A - Numerical Methods 34 Visualization and Computer Graphics Lab Jacobs University Example 2 • f(x) = ex at point c = 0. •Taylor‘stheorem: •Let •Hence,

120202: ESM4A - Numerical Methods 56

Visualization and Computer Graphics LabJacobs University

Conversion 2 <-> 8 and 2 <-> 16

• 2 <-> 8:Three consecutive bits represent one octal digit.Example:

• 2 <-> 16:Four consecutive bits represent one hexadecimal digit.