liveBook · Manning

Numerical solution

As explained in Geometry for Programmers

A numerical or numeric solution is a solution represented by evaluated numerical values rather than symbolic expressions.

A numerical solution represents unknowns with evaluated numbers rather than generalized symbols. For a system of equations, it gives a concrete set of values that satisfies the equations when such a solution can be found. section 1.6

SymPy can find numerical solutions by declaring variables, combining equations into a system, and calling solve. The resulting values can then be turned into program code. section 1.6

A two-equation system

Given Vp = 2Va and Va + Vp = 450, SymPy returns Va = 150 and Vp = 300. These numbers describe the single solution directly; replacing 450 or 2 with symbols instead produces a symbolic formula. section 1.6

Listing 1.1 Numeric solution in SymPy
from sympy import *
 
Va, Vp = symbols('Va Vp')    #1
 
solution = solve([
    Vp - Va * 2,
    Va * 1 + Vp * 1 - 450
], (Va, Vp))
 
print(solution)

This listing shows the complete SymPy workflow for obtaining a numerical solution. section 1.6

Numerical methods are especially useful for large systems: a million equations may be solved numerically, while symbolic computation can become impractical even for an 8 × 8 system. Underspecified systems are different: their solutions may form a line, plane, or hyperplane rather than one set of numbers, so they are rarely solved numerically. section 3.2.2 section 3.2.2

How Geometry for Programmers covers it

How deep it goes
Explains the SymPy workflow and scalability trade-off, but defers numerical algorithm internals.
Examples
Uses a two-variable speed-and-distance system returning Va = 150 and Vp = 300.
What you can do after
Apply via SymPy by declaring symbols, assembling equations, calling solve, and using the returned numerical values.
How it connects
Connects numerical solutions with symbolic solutions, systems of linear equations, underspecified systems, and computer algebra systems.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Geometry for Programmers. The section links point to the parts of the book it draws on.