Skip to content

Commit 4371505

Browse files
authored
Merge branch 'master' into compathelper/new_version/2022-03-14-00-47-32-908-03916490587
2 parents 966344d + bbe50a7 commit 4371505

213 files changed

Lines changed: 7741 additions & 4324 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/CI.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ jobs:
1111
matrix:
1212
version:
1313
- '1.6'
14-
- 'nightly'
1514
os:
1615
- ubuntu-latest
1716
- macOS-latest
@@ -69,4 +68,4 @@ jobs:
6968
env:
7069
JULIA_PKG_SERVER: ""
7170
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72-
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
71+
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}

Project.toml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,43 @@
11
name = "FractionalDiffEq"
22
uuid = "c7492dd8-6170-483b-af64-cefb6c377d9a"
33
authors = ["Qingyu Qu <[email protected]>"]
4-
version = "0.2.1"
4+
version = "0.3.2"
55

66
[deps]
7-
ApproxFun = "28f2ccd6-bb30-5033-b560-165f7b14dc2f"
7+
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
8+
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
89
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
10+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
11+
HypergeometricFunctions = "34004b35-14d8-5ef3-9330-4cdb6864b03a"
912
InvertedIndices = "41ab1584-1d38-5bbf-9106-f11c6c58b48f"
1013
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
14+
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
1115
Polynomials = "f27b6e38-b328-58d1-80ce-0feddd5e7a45"
12-
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
16+
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
17+
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
1318
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1419
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1520
SpecialMatrices = "928aab9d-ef52-54ac-8ca1-acd7ca42c160"
21+
ToeplitzMatrices = "c751599d-da0a-543b-9d20-d0a503d91d24"
22+
TruncatedStacktraces = "781d530d-4396-4725-bb49-402e4bee1e77"
1623
UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
1724

1825
[compat]
19-
ApproxFun = "0.12, 0.13"
26+
ArrayInterface = "0.12, 0.13"
27+
DiffEqBase = "6"
2028
FFTW = "1.0.0"
29+
ForwardDiff = "0.10"
30+
HypergeometricFunctions = "0.3.8"
2131
InvertedIndices = "1.1"
22-
Polynomials = "2.0.24, 3"
23-
QuadGK = "2"
24-
SpecialFunctions = "0.7, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13, 0.14"
25-
SpecialMatrices = "2.0.0"
32+
LoopVectorization = "0.12"
33+
Polynomials = "2.0.24, 3, 4"
34+
RecipesBase = "1.2"
35+
Reexport = "1.0"
36+
SciMLBase = "1, 2"
37+
SpecialFunctions = "0.7, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13, 0.14, 2"
38+
SpecialMatrices = "2.0.0, 3"
39+
ToeplitzMatrices = "0.7.0, 0.8"
40+
TruncatedStacktraces = "1"
2641
UnPack = "1.0.0"
2742
julia = "1.2"
2843

README.md

Lines changed: 62 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# FractionalDiffEq.jl
22

3+
34
<p align="center">
45
<img width="250px" src="https://raw.githubusercontent.com/SciFracX/FractionalDiffEq.jl/master/docs/src/assets/logo.svg"/>
56
</p>
@@ -35,6 +36,8 @@
3536
</a>
3637
</p>
3738

39+
FractionalDiffEq.jl provides FDE solvers to [DifferentialEquations.jl](https://diffeq.sciml.ai/dev/) ecosystem, including FODE(Fractional Ordianry Differential Equations), FDDE(Fractional Delay Differential Equations) and many more. There are many performant solvers available, capable of solving many kinds of fractional differential equations.
40+
3841
# Installation
3942

4043
If you have already installed Julia, you can install FractionalDiffEq.jl in REPL using Julia package manager:
@@ -45,61 +48,45 @@ pkg> add FractionalDiffEq
4548

4649
# Quick start
4750

48-
### An easy example
51+
### Fractional ordinary differential equations
4952

5053
Let's see if we have an initial value problem:
5154

52-
<p align="center">
53-
54-
<img src="https://latex.codecogs.com/svg.image?D^{0.5}y(x)=1-y" title="D^{0.5}y(x)=1-y" />
55+
$$ D^{1.8}y(x)=1-y $$
5556

56-
</p>
57-
58-
<p align="center">
59-
60-
<img src="https://latex.codecogs.com/svg.image?y(0)=0" title="y(0)=0" />
61-
62-
</p>
6357

58+
$$ y(0)=0 $$
6459

6560
So we can use FractionalDiffEq.jl to solve the problem:
6661

6762
```julia
68-
fun(x, y) = 1-y
69-
u0 = 0; T = 5; h = 0.001
70-
prob = SingleTermFODEProblem(fun, 0.5, u0, T)
71-
result = solve(prob, h, PECE())
72-
tspan = collect(0:h:T)
63+
using FractionalDiffEq, Plots
64+
fun(u, p, t) = 1-u
65+
u0 = [0, 0]; tspan = (0, 20); h = 0.001;
66+
prob = SingleTermFODEProblem(fun, 1.8, u0, tspan)
67+
sol = solve(prob, h, PECE())
68+
plot(sol)
7369
```
7470

75-
And if you plot the result, you can see the result of the fractional differential equation:
71+
And if you plot the result, you can see the result of the above IVP:
7672

77-
![Example](/docs/src/assets/simple_example.png)
73+
![Example](/docs/src/assets/example.png)
7874

7975
### A sophisticated example
8076

8177
Let's see if the initial value problem like:
8278

83-
<p align="center">
84-
85-
<img src="https://latex.codecogs.com/svg.image?y'''(t)&plus;\frac{1}{16}{^C_0D^{2.5}_t}y(t)&plus;\frac{4}{5}y''(t)&plus;\frac{3}{2}y'(t)&plus;\frac{1}{25}{^C_0D^{0.5}_t}y(t)&plus;\frac{6}{5}y(t)=\frac{172}{125}\cos(\frac{4t}{5})" title="y'''(t)+\frac{1}{16}{^C_0D^{2.5}_t}y(t)+\frac{4}{5}y''(t)+\frac{3}{2}y'(t)+\frac{1}{25}{^C_0D^{0.5}_t}y(t)+\frac{6}{5}y(t)=\frac{172}{125}\cos(\frac{4t}{5})" />
86-
87-
</p>
88-
89-
<p align="center">
79+
$$ y'''(t)+\frac{1}{16}{^C_0D^{2.5}_t}y(t)+\frac{4}{5}y''(t)+\frac{3}{2}y'(t)+\frac{1}{25}{^C_0D^{0.5}_t}y(t)+\frac{6}{5}y(t)=\frac{172}{125}\cos(\frac{4t}{5}) $$
9080

91-
<img src="https://latex.codecogs.com/svg.image?y(0)=0,\&space;y'(0)=0,\&space;y''(0)=0" title="y(0)=0,\ y'(0)=0,\ y''(0)=0" />
92-
93-
</p>
81+
$$ y(0)=0,\ y'(0)=0,\ y''(0)=0 $$
9482

9583
```julia
9684
using FractionalDiffEq, Plots
97-
T=30;h=0.05
98-
tspan = collect(0.05:h:T)
99-
rightfun(x) = 172/125*cos(4/5*x)
100-
prob = MultiTermsFODEProblem([1, 1/16, 4/5, 3/2, 1/25, 6/5], [3, 2.5, 2, 1, 0.5, 0], rightfun) #pass the parameters vector and the orders vector
101-
result = solve(prob, h, T, FODEMatrixDiscrete())
102-
plot(tspan, result, title=s, legend=:bottomright)
85+
h=0.01; tspan = (0, 30)
86+
rightfun(x, y) = 172/125*cos(4/5*x)
87+
prob = MultiTermsFODEProblem([1, 1/16, 4/5, 3/2, 1/25, 6/5], [3, 2.5, 2, 1, 0.5, 0], rightfun, [0, 0, 0, 0, 0, 0], tspan)
88+
sol = solve(prob, h, PIEX())
89+
plot(sol, legend=:bottomright)
10390
```
10491

10592
Or use the [example file](https://github.com/SciFracX/FractionalDiffEq.jl/blob/master/examples/complicated_example.jl) to plot the numerical approximation, we can see the FDE solver in FractionalDiffEq.jl is amazingly powerful:
@@ -108,106 +95,80 @@ Or use the [example file](https://github.com/SciFracX/FractionalDiffEq.jl/blob/m
10895

10996
### System of Fractional Differential Equations:
11097

111-
FractionalDiffEq.jl is a powerful tool to solve system of fractional differential equations:
98+
FractionalDiffEq.jl is a powerful tool to solve system of fractional differential equations, if you are familiar with [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl), it would be just like out of the box.
11299

113100
Let's see if we have a Chua chaos system:
114101

115-
<p align="center">
116-
117-
<img src="https://latex.codecogs.com/svg.image?\begin{cases}D^{\alpha_1}x=10.725[y-1.7802x-[0.1927(|x&plus;1|-|x-1|)]\\D^{\alpha_2}y=x-y&plus;z\\D^{\alpha_3}z=-10.593y-0.268z\end{cases}" title="\begin{cases}D^{\alpha_1}x=10.725[y-1.7802x-[0.1927(|x+1|-|x-1|)]\\D^{\alpha_2}y=x-y+z\\D^{\alpha_3}z=-10.593y-0.268z\end{cases}" />
118-
119-
</p>
102+
$$ \begin{cases}D^{\alpha_1}x=10.725[y-1.7802x-[0.1927(|x+1|-|x-1|)]\\
103+
D^{\alpha_2}y=x-y+z\\
104+
D^{\alpha_3}z=-10.593y-0.268z\end{cases} $$
120105

121106
By using the ```NonLinearAlg``` algorithms to solve this problem:
122107

123108
```julia
124109
using FractionalDiffEq, Plots
125-
function chua(t, x, k)
126-
a=10.725
127-
b=10.593
128-
c=0.268
129-
m0=-1.1726
130-
m1=-0.7872
131-
132-
if k==1
133-
f=m1*x[1]+0.5*(m0-m1)*(abs(x[1]+1)-abs(x[1]-1))
134-
y=a*(x[2]-x[1]-f)
135-
return y
136-
elseif k==2
137-
y=x[1]-x[2]+x[3]
138-
return y
139-
elseif k==3
140-
y=-b*x[2]-c*x[3]
141-
return y
142-
end
110+
function chua!(du, x, p, t)
111+
a, b, c, m0, m1 = p
112+
du[1] = a*(x[2]-x[1]-(m1*x[1]+0.5*(m0-m1)*(abs(x[1]+1)-abs(x[1]-1))))
113+
du[2] = x[1]-x[2]+x[3]
114+
du[3] = -b*x[2]-c*x[3]
143115
end
144-
145116
α = [0.93, 0.99, 0.92];
146117
x0 = [0.2; -0.1; 0.1];
147-
prob = SystemOfFDEProblem(chua, α, x0)
148-
tn = 200; h = 0.001;
149-
result = solve(prob, h, tn, NonLinearAlg())
150-
plot(result[:, 1], result[:, 2], title="Chua System", legend=:bottomright)
118+
h = 0.01; tspan = (0, 100);
119+
p = [10.725, 10.593, 0.268, -1.1726, -0.7872]
120+
prob = FODESystem(chua!, α, x0, tspan, p)
121+
sol = solve(prob, h, NonLinearAlg())
122+
plot(sol, vars=(1, 2), title="Chua System", legend=:bottomright)
151123
```
152124

153125
And plot the result:
154126

155127
![Chua](docs/src/assets/chua.png)
156128

157-
## Fractional Partial Differential Equations
158-
159-
Fractional provide powerful algorithms to solve fractional partial differential equations, let's see a diffusion example here:
160-
161-
<p align="center">
162-
163-
<img src="https://latex.codecogs.com/svg.image?_{0}^{C}\!D_{t}^{\alpha}y-&space;\frac{\partial^\beta&space;y}{\partial&space;|x|^\beta}&space;=&space;f(x,t)" title="_{0}^{C}\!D_{t}^{\alpha}y- \frac{\partial^\beta y}{\partial |x|^\beta} = f(x,t)" />
164-
165-
</p>
166-
167-
With initial and boundry conditions:
168-
169-
<p align="center">
170-
171-
<img src="https://latex.codecogs.com/svg.image?y(0,t)&space;=&space;0,&space;\quad&space;y(1,t)&space;=&space;0&space;\qquad&space;&space;\quad&space;y(x,0)&space;=&space;0" title="y(0,t) = 0, \quad y(1,t) = 0 \qquad \quad y(x,0) = 0" />
129+
## Fractional Delay Differential Equations
172130

173-
</p>
131+
There are also many powerful solvers for solving fractional delay differential equations.
174132

175-
By using the FPDE solvers in FractionalDiffEq.jl and plot the numerical approximation:
133+
$$ D^\alpha_ty(t)=3.5y(t)(1-\frac{y(t-0.74)}{19}) $$
176134

177-
![diffusion](docs/src/assets/diffusion.png)
135+
$$ y(0)=19.00001 $$
178136

179-
### ODE Example
180137

181-
FractionalDiffEq.jl is also able to solve ordinary differential equations~ Let's see an example here:
138+
With history function:
182139

183-
<p align="center">
140+
$$ y(t)=19,\ t<0 $$
184141

185-
<img src="https://latex.codecogs.com/svg.image?y''(x)&plus;y'(x)=\sin(x)" title="y''(x)+y'(x)=\sin(x)" />
142+
```julia
143+
using FractionalDiffEq, Plots
144+
ϕ(x) = x == 0 ? (return 19.00001) : (return 19.0)
145+
f(t, y, ϕ) = 3.5*y*(1-ϕ/19)
146+
h = 0.05; α = 0.97; τ = 0.8; T = 56
147+
fddeprob = FDDEProblem(f, ϕ, α, τ, T)
148+
V, y = solve(fddeprob, h, DelayPECE())
149+
plot(y, V, xlabel="y(t)", ylabel="y(t-τ)")
150+
```
186151

187-
</p>
152+
![Delayed](docs/src/assets/fdde_example.png)
188153

189-
<p align="center">
154+
## Lyapunov exponents of fractional order system
190155

191-
<img src="https://latex.codecogs.com/svg.image?y(0)=0" title="y(0)=0" />
156+
FractionalDiffEq.jl is capable of generating lyapunov exponents of a fractional order system:
192157

193-
</p>
158+
Rabinovich-Fabrikant system:
194159

160+
$$
161+
\begin{cases} D^{\alpha_1} x=y(z-1+z^2)+\gamma x\\
162+
D^{\alpha_2} y=x(3z+1-x^2)+\gamma y\\
163+
D^{\alpha_3} z=-2z(\alpha+xy)
164+
\end{cases}
165+
$$
195166

196167
```julia
197-
using FractionalDiffEq, Plots
198-
199-
T = 30; h = 0.05
200-
tspan = collect(h:h:T)
201-
f(x) = 1/2*(-exp(-x)-sin(x)-cos(x)+2)
202-
target =f.(tspan)
203-
rightfun(x) = sin(x)
204-
prob = MultiTermsFODEProblem([1, 1], [2, 1], rightfun)
205-
result = solve(prob, h, T, FODEMatrixDiscrete())
206-
plot(tspan, result, title=s, legend=:bottomright, label="ODE Numerical Solution!")
207-
plot!(tspan, target, lw=3,ls=:dash,label="ODE Analytical Solution!")
168+
julia>LE, tspan = FOLyapunov(RF, 0.98, 0, 0.02, 300, [0.1; 0.1; 0.1], 0.005, 1000)
208169
```
209170

210-
![ODE Example](docs/src/assets/ode_example.png)
171+
![RF](docs/src/assets/RFLE.png)
211172

212173
# Available Solvers
213174

benchmarks/fdde/bench.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using FractionalDiffEq, Plots, SpecialFunctions
2+
3+
phi(x)=0
4+
α=0.9; τ = 0.1
5+
f(t, y, ϕ)=2/gamma(3-α)*t^(2-α)-1/gamma(2-α)*t^(1-α)+2*τ*t-τ^2-τ-y+ϕ
6+
h = 1e-2
7+
realfun(t) = t^2-t
8+
9+
prob = FDDEProblem(f, phi, α, τ, (0, 5))
10+
sol1 = solve(prob, h, DelayPI())
11+
sol2 = solve(prob, h, DelayABM())
12+
sol3 = sove(prob, h, DelayPECE())
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using FractionalDiffEq, Plots, LinearAlgebra
2+
3+
h = 1e-2; tspan = (0, 30)
4+
rightfun(x, y) = 172/125*cos(4/5*x)
5+
multitermprob = MultiTermsFODEProblem([1, 1/16, 4/5, 3/2, 1/25, 6/5], [3, 2.5, 2, 1, 0.5, 0], rightfun, [1, 4/5, -16/25, 0, 0, 0], tspan)
6+
7+
realfun(x)=sqrt(2)*sin(4*x/5+π/4)
8+
sol1 = solve(multitermprob, h, PIEX())
9+
sol2 = solve(multitermprob, h, PIIMRect())
10+
sol3 = solve(multitermprob, h, PIIMTrap())
11+
sol4 = solve(multitermprob, h, PIPECE())
12+
#=
13+
plot(sol1)
14+
plot!(sol2)
15+
plot!(sol3)
16+
plot!(sol4)
17+
=#
18+
#plot!(collect(0:0.01:30), realfun.(collect(0:0.01:30)))
19+
20+
realsol = realfun.(collect(0:h:30))
21+
err1 = norm(sol1.u-realsol)
22+
err2 = norm(sol2.u-realsol)
23+
err3 = norm(sol3.u-realsol)
24+
err4 = norm(sol4.u-realsol)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using FractionalDiffEq, Plots
2+
3+
α = 1.8; h = 1e-2
4+
5+
# Analytical solution
6+
analytical(x) = x.^1.8 .*mittleff(1.8, 2.8, -x.^1.8)
7+
# Numerical solution
8+
fun(x, y) = 1-y
9+
#prob = SingleTermFODEProblem(fun, 1.8, [0, 0], (0, 20))
10+
prob = SingleTermFODEProblem(fun, α, [0, 0], (0, 20))
11+
sol1 = solve(prob, h, PECE())
12+
sol2 = solve(prob, h, GL())
13+
sol3 = solve(prob, h, PIEX())
14+
15+
tspan = collect(0:0.01:20)
16+
target = analytical.(tspan)
17+
18+
plot(sol1)
19+
plot!(sol2)
20+
plot!(sol3)
21+
#plot!(tspan, target, lw=3, ls=:dash, label="Analytical")

0 commit comments

Comments
 (0)