Ch1.1 Numerical Analysis

Numerical Analysis: Widely Used

  • Numerical analysis underlies many fields which require numerical answers to mathematical questions.
  • From video games to climate science, engineering & physics to psychology, numerical analysis performs the calculations we use daily.
  • Medical professionals use numerical analysis to process advanced imagery.
  • Numerical analysis supports almost any field when computers are used to solve mathematical problems.

Numerical Analysis Constraints

  • Limited amount of computer memory, for storing and processing data.
  • Computers only represent a finite collection of numbers.
  • Most numbers on the number line \( (-\infty, \infty) \), or even just \( [0,1] \), are absent from computer's number line. Thus most computed results are estimates of the actual solution.
  • Another constraint is computational time. Running algorithms for numerical methods, data storage and access, and so on, takes time.
  • Fast and accurate numerical methods are not always readily available, and may take time for numerical analysts and programmers to create.

Numerical View of Functions

  • In precalculus, we learn that a function can be represented in terms of a formula, a graph and/or a table of values (x-y table).
  • The table of values is considered a numerical representation of the function.
  • Numerical values for a function can be found by data collection or by using formulas (if one is available).
  • In computational science, numerical representations are often the only way solutions to equations can be found.
x y
0 1
1 3
2 5

Example: Representations of a Function

For \( f(x) = 2x+1 \):

x <- c(0,1,2)
f <- 2*x+1
f
[1] 1 3 5
x y
0 1
1 3
2 5

title

Numerical Approach

  • Using analytical methods (algebra, formulas from calculus and other math classes) to solve for exact solutions are preferred.
  • However, numerical methods are often the only way to solve problems in science, engineering, business, etc.

https://calcworkshop.com title

x <- c(0,1,2)
f <- 2*x+1
f
[1] 1 3 5

Numerical Methods vs Numerical Analysis

  • Numerical methods is concerned with the different formulas available for common problems in computational science.
  • Numerical analysis is concerned with analzying how fast, efficient and accurate the different numerical methods are.

title

Example: Square Root of 2

In figure below, the Babylonian method for approximating \( \sqrt{2} \) is stable, fast and accurate (but not Method X…).

\[ \begin{align*} x_{k+1} & = \frac{x_{k}}{2} + \frac{1}{x_k} \\ x_{k+1} & = \left(x_k^2 -2\right)^2 + x_k \end{align*} \]

https://en.wikipedia.org/wiki/Numerical_analysis title

R Code for Babylonian Method

babylonian <- function(x0,m) {
  # x0 = initial value
  # m = number of iterations

  # Iteration function:
  g <- function(x){x/2 + 1/x}

  # Start by displaying initial value
  cat("n = ", 0,",", "x(n) = ", x0, "\n")

  # Iteration loop
  for(n in 1:m) {
    x1 <- g(x0)
    x0 <- x1
    cat("n = ", n,",", "x(n) = ", x1, "\n")  }
  }

Example: Babylonian Method

title

\[ \small{x_{k+1} = \frac{x_{k}}{2} + \frac{1}{x_k}} \]

sqrt(2)
[1] 1.414214
babylonian(1.4,3)
n =  0 , x(n) =  1.4 
n =  1 , x(n) =  1.414286 
n =  2 , x(n) =  1.414214 
n =  3 , x(n) =  1.414214 
babylonian(1.42,3)
n =  0 , x(n) =  1.42 
n =  1 , x(n) =  1.414225 
n =  2 , x(n) =  1.414214 
n =  3 , x(n) =  1.414214 

R Code for Method X

methodX <- function(x0,m) {
  # x0 = initial value
  # m = number of iterations

  # Iteration function:
  g <- function(x){(x^2 -2)^2 + x}

  # Start by displaying initial value
  cat("n = ", 0,",", "x(n) = ", x0, "\n")

  # Iteration loop
  for(n in 1:m) {
    x1 <- g(x0)
    x0 <- x1
    cat("n = ", n,",", "x(n) = ", x1, "\n")  }
  }

Example: Method X

title

\[ \small{x_{k+1} = \left(x_k^2 -2\right)^2 + x_k} \]

sqrt(2)
[1] 1.414214
methodX(1.4,8)
n =  0 , x(n) =  1.4 
n =  1 , x(n) =  1.4016 
n =  2 , x(n) =  1.402861 
n =  3 , x(n) =  1.403884 
n =  4 , x(n) =  1.404732 
n =  5 , x(n) =  1.405446 
n =  6 , x(n) =  1.406057 
n =  7 , x(n) =  1.406586 
n =  8 , x(n) =  1.407049 

Example: Method X

title

\[ \small{x_{k+1} = \left(x_k^2 -2\right)^2 + x_k} \]

sqrt(2)
[1] 1.414214
methodX(1.42,8)
n =  0 , x(n) =  1.42 
n =  1 , x(n) =  1.420269 
n =  2 , x(n) =  1.420564 
n =  3 , x(n) =  1.420888 
n =  4 , x(n) =  1.421246 
n =  5 , x(n) =  1.421643 
n =  6 , x(n) =  1.422087 
n =  7 , x(n) =  1.422586 
n =  8 , x(n) =  1.42315 

Numerical Computation & Error Analysis

  • Numerical analysis is more than the search for numerical solutions to mathematical problems.
  • It is also the search for usable estimates of those solutions.
  • Sometimes an error analysis is more extensive than coding the numerical method that produces the solution.
  • From there, we can evaluate how usable our estimate is.