My bachelor project on solving the Calculus of variations problems using symbolic mathematics (2018).
I participated with this project at the IX International Scientific and Practical Conference named after A.I. Kitov "Information Technologies and Mathematical Methods in Economics and Management" (link).
My presentation about this project.
According to Wikipedia:
The calculus of variations is a field of mathematical analysis that uses variations, which are small changes in functions and functionals, to find maxima and minima of functionals: mappings from a set of functions to the real numbers. Functionals are often expressed as definite integrals involving functions and their derivatives. Functions that maximize or minimize functionals may be found using the Euler–Lagrange equation of the calculus of variations.
The definition above might seem quite difficult to understand, so let's consider the simplest problem:
This is the task of finding an extrema in continuously differentiable functions space , where:
- functional to maximize/minimize,
- fixed closed line segment,
- continuously differentiable function,
- function derivative,
- boundary conditions.
Functions that maximize or minimize functionals may be found using the Euler–Lagrange equation of the calculus of variations:
- partial derivative of w.r.t. ,
- partial derivative of w.r.t. .
Arbitrary constants arising when solving this differential equation, find them from the given boundary conditions.
- Simplest problem
- Boltz problem
- Isoperimetric problem
- Higher derivatives problem
- Multidimensional problem
More about each task in project wiki.
First, install the package:
pip install calculus-of-variations
Usage for example above:
import calculus_of_variations
solver = calculus_of_variations.SimplestSolver(
L="x_diff ** 2 + t * x",
t0="0", t1="1",
x0="0", x1="0",
)
solver.solve()
# integral from 0 to 1 of (x_diff ** 2 + t * x)dt -> extr
# x(0) = 0
# x(1) = 0
# general_solution: C1 + C2*t + t**3/12
# coefficients: {C1: 0, C2: -1/12}
# particular_solution: t**3/12 - t/12
# extrema_value: -1/180
Other cases:
# Simplest problem
solver = calculus_of_variations.SimplestSolver(
L="x_diff ** 2",
t0="0", t1="1",
x0="0", x1="1",
)
solver.solve()
# Boltz problem
solver = calculus_of_variations.BoltzSolver(
L="x_diff ** 2 + 2 * x",
l="x_t0 ** 2",
t0="0", t1="1",
)
solver.solve()
# Isoperimetric problem
solver = calculus_of_variations.IsoperimetricSolver(
f0="x_diff ** 2",
t0="0", t1="1",
x0="0", x1="1",
f_list="x",
alpha_list="0",
)
solver.solve()
# Higher derivatives problem
solver = calculus_of_variations.HigherDerivativesSolver(
n="2",
L="x_diff_2 ** 2",
t0="0", t1="1",
x0="0", x1="0",
x0_array="0",
x1_array="1",
)
solver.solve()
# Multidimensional problem
solver = calculus_of_variations.MultidimensionalSolver(
L="x1_diff**2 + x2_diff**2",
t0="0", t1="1",
x1_0="0", x1_1="1",
x2_0="0", x2_1="1",
)
solver.solve()
For specific examples see examples.sh.
List of allowed functions that you can use as parameters: link.
The project supports simple web-interface for solving problems.
You can specify host (--host
) and port (--port
) (default values: host: 127.0.0.1
and port: 8050
):
# Simplest problem
python -m web_interface.simplest_problem_dash --host "127.0.0.1" --port 8050
# Boltz problem
python -m web_interface.boltz_problem_dash --host "127.0.0.1" --port 8050
# Isoperimetric problem
python -m web_interface.isoperimetric_problem_dash --host "127.0.0.1" --port 8050
# Higher derivatives problem
python -m web_interface.higher_derivatives_problem_dash --host "127.0.0.1" --port 8050
# Multidimensional problem
python -m web_interface.multidimensional_problem_dash --host "127.0.0.1" --port 8050
You can also launch web-interface using docker.
To build docker image run:
docker image build -t calculus_of_variations .
You can also pull image from Docker Hub:
docker pull dayyass/calculus_of_variations
To start docker container run (example for simplest_problem_dash):
docker container run -d -p 8050:8050 --name calculus_of_variations calculus_of_variations python -m web_interface.simplest_problem_dash --host 0.0.0.0 --port 8050
To access web-interface go to http://localhost:8050
To launch tests run the following commands:
python -m unittest discover
To use pre-commit hooks run:
pre-commit install
To measure code coverage run the following commands:
coverage run -m unittest discover && coverage report -m
Python >= 3.6
If you use calculus-of-variations in a scientific publication, we would appreciate references to the following BibTex entry:
@misc{dayyass2018variations,
author = {El-Ayyass, Dani},
title = {Calculus of Variations problems solving using symbolic mathematics},
howpublished = {\url{https://github.com/dayyass/calculus-of-variations}},
year = {2018}
}