In ortools if you have only 0-1 variables you can either use CP-SAT from
from ortools.sat.python import cp_model
or you can use
from ortools.linear_solver import pywraplp
solver = pywraplp.Solver.CreateSolver('SAT')
Are these solvers the same and if not, what is the difference?
Pywraplp supports linear equations/inequations with floating point coefficients.
CP-SAT is integral only, but support much more constraints (quadratic scheduling, routing...) in addition to linear constraints.
pywraplp with the SAT backend scales all coefficients to achieve linear constraints that only have integral coefficients, then calls the CP-SAT solver.
Related
I used Scipy.optimize.differential_evolution to estimate parameters for my models; however, unlike Curve_fit, it cannot retire covariance. How can I calculate the uncertainties of my parameters?
You could start off with differential_evolution to find the minimum, then follow-up with a leastsq or curve_fit to estimate the uncertainties. Other ways of estimating the uncertainties are to calculate the Hessian matrix by using e.g. finite differences
I am developing a small kinetic Monte Carlo code to study atomic evolutions in a material and need to solve several linear and non-linear equations with a high accuracy. My main issue is in finding complex roots of a non-linear equation.
Which C++ library is perfect for solving a non-linear set of equations with complex roots? I am already using Eigen and Ceres in my codes, but it seems that they only can find "real" roots and not "complex" ones.
All recommendations and ideas are appreciated in advance.
Update-1:
For example, Eigen provides a nonlinear optimization module,
https://eigen.tuxfamily.org/dox/unsupported/group__NonLinearOptimization__Module.html
which uses (1)Levenberg Marquardt algorithm and (2)Powell hybrid "dogleg" method to find roots and extremums of a nonlinear set of equations. As far as I know, these methods can't find complex roots if any.
I'm using the MATLAB's function 'pdepe' to solve a problem with some partial differential equations, a parabolic one.
I need to know the kind of numerical method that function uses, 'cause I have to notify this in a report.
The description of the function in MathWorks is "Solve initial-boundary value problems for systems of parabolic and elliptic PDEs in one space variable and time". Is it a finite difference method?
Thanks for helping me.
Taken from the Matlab 2016b documentation for pdepe:
The time integration is done with ode15s. pdepe exploits the
capabilities of ode15s for solving the differential-algebraic
equations that arise when Equation 1-3 contains elliptic equations,
and for handling Jacobians with a specified sparsity pattern.
Also, from the ode15s documentation:
ode15s is a variable-step, variable-order (VSVO) solver based on the
numerical differentiation formulas (NDFs) of orders 1 to 5.
Optionally, it can use the backward differentiation formulas (BDFs,
also known as Gear's method) that are usually less efficient
As indicated by Alessandro Trigilio, ode15s is used to advance the solution forward in time. Exactly what the function is advancing in time is a semi-discrete, second-order Galerkin formulation for non-singular problems or a semi-discrete, second-order Petrov-Galerkin formulation for singular problems (polar or spherical meshes that include the origin). As such, the spatial discretization is finite element in nature.
Solving system of constrained linear and non-linear equations in MATLAB
I'm solving a FEM problem in MATLAB with use of the direct stiffness method. The problem is now formulated as a system of non linear equations:
KU=F or CF=U with C = K^{-1}.
the problem is formulated in 3-Dd and has over 200 nodes. The model is used as a deformation estimator, the force is always the input and the deformation output. So there are a lot of linear equations. Now this problem needs to be extended, 2 types of constraints need to be implemented. Some of the nodes have to be constrained so that they only can move in a circular motion around a given point. And some of the nodes have to be bound with a maximum amount of deformation.
in total there will hundreds of equations of the form equations of the form:
a_1 X(1) + a_2 X(2) + ... - F(1) = 0
about 10 equality constraints of a nonlinear form like (could also be a sinusoid):
X(1)^2 + X(2)^2 = L
and 10 inequality constraints of the form:
X(1) < 30\pi/180
What is the best method to solve a nonlinear system of equations with constraints of this type simultaneously? Is it possible to use fsolve? Or fmincon? I've been looking into solvers but I can't find a solid conclusion on what solver can handle all these equation types at once and what would be most efficient in terms of computation time.
Without knowing too much of your type of problem, you should have a look on more specific mathematical-optimisation tools, where you can write your "similar" constraints only once, decide to which dimensions do they apply, and the language then expand them accordingly.
For the solver-engine for non-linear problem I would suggest IPOPT. It's free and it has very good performances.
For the modelling tools, you have the choice between dedicated mathematical-optimisation packages, like GAMS or AMPL, or - more and more common nowadays - libraries that extend general-purposes languages into the domain of mathematical optimisation (in this second case I would suggest Pyomo for Python or JuML for Julia)
I have to identify an ARX under some linear constraints, this means that I have a quadratic programming with linear equality constraints problem.
One way is to use the following equations in the red boxes. A possible disadvantage in this case is the calculation of the matrix inversions (sometimes Matlab gives me the warning: Matrix is close to singular or badly scaled)
Another way is to use in Matlab the command: quadprog()
Another way is to use in Matlab the command: lsqlin()
Which of these three methods is the best one?
Which is the most robust numerically?