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 >
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
4043If 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
5053Let'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
6560So 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
8177Let'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
9684using 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
10592Or 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
113100Let'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
121106By using the ``` NonLinearAlg ``` algorithms to solve this problem:
122107
123108``` julia
124109using 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 ]
143115end
144-
145116α = [0.93 , 0.99 , 0.92 ];
146117x0 = [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
153125And 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
0 commit comments