Skip to content
Snippets Groups Projects
Commit c6a410a4 authored by Jialei Ding's avatar Jialei Ding
Browse files

Update 2 files

- /book/numerical_methods/overview.md
- /book/numerical_methods/1-revision-of-concepts.ipynb
parent 8baa8370
No related branches found
No related tags found
1 merge request!381Review Jialei
%% Cell type:markdown id: tags:
# Revision of Concepts
%% Cell type:markdown id: tags:
## Classification of Differential Equations
%% Cell type:markdown id: tags:
```{note}
**Important things to retain from this block:**
* Identify characteristics of differential equations
* Understanding how numerical and analytical solutions might differ as we get to more complex problems which need simplification
* Understand how numerical and analytical solutions might differ as we get to more complex problems which need simplification
* Remember that analytical solutions are not always possible
```
%% Cell type:markdown id: tags:
Differential equations can be classified in Ordinary Differential Equations (ODEs) and Partial Differential Equations (PDEs). **ODEs** have derivatives with respect to a **single** independent variable (either time **or** space), for example
Differential equations can be classified as Ordinary Differential Equations (ODEs) and Partial Differential Equations (PDEs). **ODEs** have derivatives with respect to a **single** independent variable (either time **or** space), for example:
$$
\frac{d x(t)}{d t} = \cos t
$$
describes the change rate of the variable $x$ in **time $t$**.
**PDEs** have derivatives with respect to **multiple** independent variables (often time **and** space), for example:
$$
\frac{\partial c(x,t)}{\partial t} + u\frac{\partial c(x,t)}{\partial x} = 0
$$
describes the propagation of the concentration $c$ in **time $t$** along **dimension $x$**.
The classification can be done more precisely, by its order and linearity (linear or non-linear). The order refers to the highest derivative while non-linear equations are those in which the dependent variable or its derivative(s) are non linear (exponential, sine or with a power different than 1). See the following examples:
The classification can be done more precisely by the equation's order and linearity (linear or non-linear). The order refers to the highest derivative while non-linear equations are those in which the dependent variable or its derivative(s) are non linear (exponential, sine or with a power different than 1). See the following examples:
$$
\frac{d^3y}{dx^3} - x\frac{d^2y}{dx^2} + y = 0 \qquad \text{third-order linear ODE}
$$
$$
\frac{dy}{dx} = y^2 + x \qquad \text{first-order non-linear ODE}
$$
$$
\frac{d^2y}{dx^2} + y\left(\frac{dy}{dx}\right)^2 = \sin(y) \qquad \text{second-order non-linear ODE}
$$
%% Cell type:markdown id: tags:
## Analytical vs Numerical Solutions
%% Cell type:markdown id: tags:
Equations can be solved in two ways: anaylitically and numerically. The analytical solution is **exact** while a numerical solution requires computational methods to **approximate** the solution. So why would we use anything other than analytical solutions? Well, analytical solutions are difficult/impossible to find for complex equations, specially when the problem involves a complex geometry. This complexity will be treated later in the book. For now, let's illustriate analytical and numerical solutions considering a simple problem.
Equations can be solved in two ways: anaylitically and numerically. The analytical solution is **exact** while a numerical solution requires computational methods to **approximate** the solution. So, why would we use anything other than analytical solutions? Well, analytical solutions are difficult/impossible to find for complex equations, specially when the problem involves a complex geometry. This complexity will be treated later in the book. For now, let's illustriate analytical and numerical solutions considering a simple problem.
:::{card}
> Find the value $x$ for $f(x)=3x-2$ when $f(x) = 0$ in the interval $[0,1]$.
**Analytical Solution**
$$ f(x) = 0 \Leftrightarrow 3x-2=0 \Leftrightarrow x = \frac{2}{3}=0.666666666666666..$$
Note that there is no need for any extra computation. You can say that there is only **one computation needed**: the assignment of the $x$ value.
:::
%% Cell type:markdown id: tags:
:::{card} **Numerical Solution**
The code below shows an iterative method to find the x value.
:::
%% Cell type:code id: tags:
``` python
def f(x):
return 3*x-2
dx = 0.001
for i in range(1000):
x = dx*i
if f(x) * f(x+dx) < 0:
print("Number of computations needed to find a solution",i*4)
break
print("Answer x = ", x+dx)
```
%% Output
Number of computations needed to find a solution 2664
Answer x = 0.667
%% Cell type:markdown id: tags:
Note that the 2664 computations needed is highly dependent on the method (this one is not very efficient). Here the search starts at x=0 and increases in steps of 0.001, which also limits the accuracy of the solution.
:::{card} Exercise
Let us now look to another simple example:
> Find the value $x$ for $f(x) = 3\sin(x)-2$ when $f(x) = 0$ in the interval $[0,1]$.
**Analytical Solution**
$$ f(x) = 0 \Leftrightarrow 3\sin(x)-2=0 \Leftrightarrow x = \arcsin\left(\frac{2}{3}\right) = 0.7297276562269663..$$
:::
%% Cell type:markdown id: tags:
:::{card}
**Numerical Solution**
:::
%% Cell type:code id: tags:
``` python
import math
def f(x):
return 3*math.sin(x)-2
dx = 0.001
for i in range(1000):
x = dx*i
if f(x) * f(x+dx) < 0:
print("Number of computations needed to find a solution",i*4)
break
print("Answer x = ", x+dx)
```
%% Output
Number of computations needed to find a solution 2916
Answer x = 0.73
%% Cell type:markdown id: tags:
Note that there is no attempt to solve f(x) directly. Only the function is defined and the exact same steps of the previous problem are followed.
......
# Bridging the Gap in Civil Engineering & Geoscience
Civil engineering and geosciences now modernised to augment experimental observations with precise numerical techniques, for the analysis and design complex structures. In this regard, the Finite Difference Method (FDM) is a fundamental and indispensable numerical approach, which plays a pivotal role in solving differential equations that govern physical phenomena.
Civil Engineering and Geosciences are now modernised to augment experimental observations with precise numerical techniques, for the analysis and design complex structures. In this regard, the Finite Difference Method (FDM) is a fundamental and indispensable numerical approach, which plays a pivotal role in solving differential equations that govern physical phenomena.
These phenomena include and are not limited to heat flow through media, the distribution of stresses in solid structures, fluid flow through porous media, and pollutant dispersion in the air and water. Solving the differential equations that govern these phenomena is often infeasible for the complex geometries and boundary conditions that are encountered in engineering.
This is where these numerical methods and FDMs come in indispensable as it systematically discretizes the expressions, transforming them into algebraic equations that can be solved numerically on a computer. This approach provides engineers with the flexibility to model and analyze a wide range of scenarios, optimize designs, ensure safety, reduce costs, and predict failures too.
\ No newline at end of file
This is where these numerical methods and FDMs become indispensable as it systematically discretizes the expressions, transforming them into algebraic equations that can be solved numerically on a computer. This approach provides engineers with the flexibility to model and analyze a wide range of scenarios, optimize designs, ensure safety, reduce costs, and predict failures.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment