The following tutorials are an introduction to solving linear and nonlinear equations with Python. The solution to linear equations is through matrix operations while sets of nonlinear equations require a solver to numerically find a solution.
Sympy is a package for symbolic solutions in Python that can be used to solve systems of equations.
$$2x^2+y+z=1$$ $$x+2y+z=c_1$$ $$-2x+y=-z$$
When solved in an IPython environment such as a Jupyter notebook, the result is displayed as:
$$x=-\frac{1}{2}+\frac{\sqrt{3}}{2}$$ $$y=c_1 - \frac{3 \sqrt{3}}{2} +\frac{3}{2}$$ $$z=-c_1 - \frac{5}{2} +\frac{5 \sqrt{3}}{2}$$
and a second solution:
$$x=-\frac{1}{2}-\frac{\sqrt{3}}{2}$$ $$y=c_1 + \frac{3 \sqrt{3}}{2} +\frac{3}{2}$$ $$z=-c_1 - \frac{5}{2} -\frac{5 \sqrt{3}}{2}$$
The same approach applies to linear or nonlinear equations.
Nonlinear equations may have multiple solutions. An example from engineering is the Redlich/Kwong Equation of State (EOS) that has 3 roots (solutions) that are the liquid volume, the vapor volume, and an extra root that isn't physically meaningful.
$$P = \frac{R_g \, T}{V-b} - \frac{a}{T^{1/2} \, V \, \left(V+b\right)}$$
where T is the temperature, V is the molar volume, `R_g` is the universal gas constant, and a and b are compound-specific constants. The solution for the molar volume of ethane for each phase at T = 77°C and P = 1 bar is shown below with Scipy fsolve and Gekko. For ethane, a = 2.877e8 cm^6 K^0.5 bar / mol^2 and b = 60.211 cm^3 / mol. The ideal gas law is a guess of the vapor volume and 1.1*b is a guess of the liquid volume.
Linear and nonlinear equations can also be solved with Excel and MATLAB. Click on the appropriate link for additional information and source code.
The Gekko Optimization Suite with a Python interface is optimization software for mixed-integer and differential algebraic equations. It is coupled with large-scale solvers for linear, quadratic, nonlinear, and mixed integer programming (LP, QP, NLP, MILP, MINLP). Modes of operation include data reconciliation, real-time optimization, dynamic simulation, and nonlinear predictive control.