# 2022-08-24 Finite Differences

## Contents

# 2022-08-24 Finite Differences#

## Last time#

General shape of PDE solvers and stakeholders

Comparing/plotting cost and accuracy

Learning strategy

## Today#

Discussion and scoping

Evaluating derivatives

Taylor series and truncation error

Stability

## Examples of PDE#

Navier-Stokes (viscous fluids)

nonlinear

incompressible or compressible

Elasticity

linear elasticity

hyperelasticity (geometric nonlinear + material nonlinearity)

time dependent (dynamics) or steady state

Hamilton-Jacobi-Bellman

optimal control

Wave equations

acoustics

elasticity

electromagnetics

frequency domain

# Choices in scoping the class#

## Theory#

Analysis first, confirm using numerics. Limited to simpler models.

## Applied#

Numerics first, pointers to useful theory.

## Build from scratch#

Limited to simpler models, but you’ll understand everything under the hood.

## Build using libraries#

More installation and software layers, but can solve more interesting problems.

# Consider the boundary value problem: find \(u\):#

We say

\(f(x)\) is the “forcing”

the left boundary condition is Dirichlet

the right boundary condition is Neumann

We need to choose

how to represent \(u(x)\), including evaluating it on the boundary,

how to compute derivatives of \(u\),

in what sense to ask for the differential equation to be satisfied,

where to evaluate \(f(x)\) or integrals thereof,

how to enforce boundary conditions.

# Finite Difference/collocation approach to solve \(u\):#

Represent the function \(u(x)\) by its values \(u_i = u(x_i)\) at a discrete set of points

\[ -1 = x_1 < x_2 < \dotsb < x_n = 1 . \]The FD framework does not uniquely specify the solution values at other points

Compute derivatives at \(x_i\) via differencing formulas involving a finite number of neighbor points (independent of the total number of points \(n\)).

FD methods ask for the differential equation to be satisfied pointwise at each \(x_i\) in the interior of the domain.

Evaluate the forcing term \(f\) pointwise at \(x_i\).

Approximate derivatives at discrete boundary points (\(x_n = 1\) above), typically using one-sided differencing formulas.

# Computing a derivative#

```
using Plots
default(linewidth=3)
n = 41
h = 6 / (n - 1)
x = LinRange(-3, 3, n)
u = sin.(x)
plot(x, u, marker=:circle)
```

```
u_x = cos.(x)
fd_u_x = (u[2:end] - u[1:end-1]) / h
plot(x, u_x)
plot!(x[1:end-1], fd_u_x, marker=:circle)
```

# How accurate is it?#

Without loss of generality, we’ll approximate \(u'(x_i = 0)\), taking \(h = x_{i+1} - x_i\).

and substitute into the differencing formula

*first order accurate*.