using DifferentialEquations
f(u,p,t) = 1.01*u
= 1/2
u0 = (0.0,1.0)
tspan = ODEProblem(f,u0,tspan)
prob = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8)
sol
using Plots
plot(sol,linewidth=5,title="Solution to the linear ODE with a thick line",
="Time (t)",yaxis="u(t) (in μm)",label="My Thick Line!") # legend=false
xaxisplot!(sol.t, t->0.5*exp(1.01t),lw=3,ls=:dash,label="True Solution!")
Paquetes de cálculo científico
SciML
SciML is the combination of scientific computing techniques with machine learning
Ecuaciones Diferenciales
ModelingToolkit.jl
ModelingToolkit.jl is a modeling language for high-performance symbolic-numeric computation in scientific computing and scientific machine learning. It then mixes ideas from symbolic computational algebra systems with causal and acausal equation-based modeling frameworks to give an extendable and parallel modeling system. It allows for users to give a high-level description of a model for symbolic preprocessing to analyze and enhance the model. Automatic symbolic transformations, such as index reduction of differential-algebraic equations, make it possible to solve equations that are impossible to solve with a purely numeric-based technique.
ModelingToolkit.jl
una capa más sobre DifferentialEquations
using ModelingToolkit
@variables t x(t) # independent and dependent variables
@parameters τ # parameters
@constants h = 1 # constants have an assigned value
= Differential(t) # define an operator for the differentiation w.r.t. time
D
# your first ODE, consisting of a single equation, the equality indicated by ~
@named fol = ODESystem([D(x) ~ (h - x) / τ])
using DifferentialEquations: solve
= ODEProblem(fol, [x => 0.0], (0.0, 10.0), [τ => 3.0])
prob # parameter `τ` can be assigned a value, but constant `h` cannot
= solve(prob)
sol
using Plots
plot(sol)
JumpProcesses.jl
FeNICS.jl
FEniCS.jl is a wrapper for the FEniCS library for finite element discretizations of PDEs. This wrapper includes three parts:
Installation and direct access to FEniCS via a Conda installation. Alternatively one may use their current FEniCS installation. A low-level development API and provides some functionality to make directly dealing with the library a little bit easier, but still requires knowledge of FEniCS itself. Interfaces have been provided for the main functions and their attributes, and instructions to add further ones can be found here. A high-level API for usage with DifferentialEquations. An example can be seen solving the heat equation with high order adaptive timestepping.
Ecuaciones en Derivadas Parciales
Gridap.jl
Gridap provides a set of tools for the grid-based approximation of partial differential equations (PDEs) written in the Julia programming language. The main motivation behind the development of this library is to provide an easy-to-use framework for the development of complex PDE solvers in a dynamically typed style without sacrificing the performance of statically typed languages. The library currently supports linear and nonlinear PDE systems for scalar and vector fields, single and multi-field problems, conforming and nonconforming finite element discretizations, on structured and unstructured meshes of simplices and hexahedra.
It has a very reach library of worked examples
JuliaFEM
The JuliaFEM project develops open-source software for reliable, scalable, distributed Finite Element Method.
Optimización: JuMP.jl
JuMP is a domain-specific modeling language for mathematical optimization embedded in Julia. It currently supports a number of open-source and commercial solvers for a variety of problem classes, including linear, mixed-integer, second-order conic, semidefinite, and nonlinear programming.
JuMP is a package for Julia. From Julia, JuMP is installed by using the built-in package manager.
import Pkg
Pkg.add("JuMP")
You also need to include a Julia package which provides an appropriate solver. One such solver is HiGHS.Optimizer, which is provided by the HiGHS.jl package.
import Pkg
Pkg.add("HiGHS")
Ejemplo
Limitaciones y alternativas
Even if your problem is differentiable, if it is unconstrained there is limited benefit (and downsides in the form of more overhead) to using JuMP over tools which are only concerned with function minimization.
Otras opciones
Cálculo simbólico
Symbolics.jl
using Symbolics
@variables x y
\[ \begin{equation} \left[ \begin{array}{c} x \\ y \\ \end{array} \right] \end{equation} \]
= x^2 + y z
\[ \begin{equation} y + x^{2} \end{equation} \]
simplify(2x + 2y)
\[ \begin{equation} 2 x + 2 y \end{equation} \]
Derivadas
@variables t g(t)
= Differential(t) Dt
(::Differential) (generic function with 2 methods)
= expand_derivatives(Dt(t*g)) expression
\[ \begin{equation} t \frac{\mathrm{d} g\left( t \right)}{\mathrm{d}t} + g\left( t \right) \end{equation} \]
= substitute(expression, Dict([g => t])) expr2
\[ \begin{equation} t + t \frac{\mathrm{d}}{\mathrm{d}t} t \end{equation} \]
expand_derivatives( expr2 )
\[ \begin{equation} 2 t \end{equation} \]
### Limitaciones
There is a list available of known missing features.
SymPy.jl
SymPy is a Python library for symbolic mathematics.
This package is a wrapper using PyCall
With the excellent PyCall package of julia, one has access to the many features of the SymPy library from within a Julia session.
It requires Python to run in the background. To install it sometimes it is needed to make a few
using Pkg
Pkg.add("Conda") # if needed
using Conda
update() Conda.
The only point to this package is that using PyCall to access SymPy is somewhat cumbersome.