NSolve

NSolve[expr,vars]

attempts to find numerical approximations to the solutions of the system expr of equations or inequalities for the variables vars.

NSolve[expr,vars,Reals]

finds solutions over the domain of real numbers.

Details and Options

  • The system expr can be any logical combination of:
  • lhs==rhsequations
    lhs!=rhsinequations
    lhs>rhs or lhs>=rhs inequalities
    exprdomdomain specifications
    {x,y,}regregion specification
    ForAll[x,cond,expr]universal quantifiers
    Exists[x,cond,expr]existential quantifiers
  • NSolve[{expr1,expr2,},vars] is equivalent to NSolve[expr1&&expr2&&,vars].
  • A single variable or a list of variables can be specified.
  • NSolve gives solutions in terms of rules of the form:
  • {}no solutions
    {{x->solx,y->soly,},}several solutions
    {{}}solution set is full dimensional
  • When a single variable is specified and a particular root of an equation has multiplicity greater than one, NSolve gives several copies of the corresponding solution.
  • NSolve[expr,vars] assumes by default that quantities appearing algebraically in inequalities are real, while all other quantities are complex.
  • In NSolve[expr,vars,Reals] all variables, parameters, constants, and function values are restricted to be real.
  • NSolve[expr&&varsReals,vars,Complexes] solves for real values of variables, but function values are allowed to be complex.
  • NSolve[,xreg,Reals] constrains x to be in the region reg. The different coordinates for x can be referred to using Indexed[x,i].
  • NSolve deals primarily with linear and polynomial equations.
  • The following options can be given:
  • MaxRoots Automaticmaximum number of roots returned
    Method Automaticwhat method should be used
    RandomSeeding1234the seeding of pseudorandom generators
    VerifySolutions Automaticwhether to verify solutions
    WorkingPrecision Automaticprecision to be used in computations
  • Possible Method settings include "EndomorphismMatrix", "Homotopy", "Monodromy", and "Symbolic". »

Examples

open allclose all

Basic Examples  (6)

Approximate solutions to a polynomial equation:

Approximate real solutions to a polynomial equation:

Find three approximate solutions to a polynomial equation of a high degree:

Approximate solutions to a system of polynomial equations:

Approximate real solutions to a system of polynomial equations:

Solve equations in a geometric region:

Scope  (48)

Complex Equations in One Variable  (10)

Univariate polynomial equations:

Polynomial equations with inexact coefficients:

Polynomial equations with multiple roots:

Find five roots of a polynomial of a high degree:

Algebraic equations:

Transcendental equations:

Find all solutions:

Specify the number of solutions returned:

Univariate elementary function equations over bounded regions:

Univariate holomorphic function equations over bounded regions:

Equation with a purely imaginary period over a vertical stripe in the complex plane:

Find all solutions:

Unrestricted transcendental function equations:

Systems of Complex Equations in Several Variables  (9)

Systems of linear equations:

Linear equations with inexact coefficients:

Underdetermined systems of linear equations:

Linear equations with no solutions:

Systems of polynomial equations:

Find five out of a trillion roots of a polynomial system:

Underdetermined systems of polynomial equations:

Algebraic equations:

Transcendental equations:

Specify the number of solutions returned:

Real Equations in One Variable  (11)

Polynomial equations:

Polynomial equations with multiple roots:

Algebraic equations:

Piecewise equations:

Transcendental equations, solvable using inverse functions:

Transcendental equations, solvable using special function zeros:

Transcendental inequalities, solvable using special function zeros:

Exp-log equations:

High-degree sparse polynomial equations:

Algebraic equations involving high-degree radicals:

Equations involving irrational real powers:

Tame elementary function equations:

Elementary function equations in bounded intervals:

Holomorphic function equations in bounded intervals:

Systems of Real Equations and Inequalities in Several Variables  (9)

Linear systems:

Polynomial systems:

Quantified polynomial systems:

Algebraic systems:

Piecewise systems:

Transcendental systems solvable using inverse functions:

Systems exp-log in the first variable and polynomial in the other variables:

Quantified system:

Systems elementary and bounded in the first variable and polynomial in the other variables:

Quantified system:

Systems holomorphic and bounded in the first variable and polynomial in the other variables:

Quantified system:

Systems with Mixed Variable Domains  (1)

Mixed real and complex variables:

Geometric Regions  (8)

Solve over special regions in 2D:

Plot it:

Solve over special regions in 3D:

Plot it:

An implicitly defined region:

A parametrically defined region:

Derived regions:

Plot it:

Regions dependent on parameters:

Plot it:

Find values of parameters , , and for which the circles contain the given points:

Plot it:

Use to specify that is a vector in :

In this case is a vector in :

Generalizations & Extensions  (1)

All variables are solved for:

Working precision can be given as the last argument:

Options  (10)

MaxRoots  (4)

Find out of roots of a polynomial:

Find out of roots of a polynomial system:

Find out of infinitely many solutions of a transcendental system:

With the default Automatic setting NSolve may not give all solutions:

With MaxRootsInfinity, NSolve attempts to find all solutions:

Method  (4)

Solve a square polynomial system using the automatically chosen method:

Use the "EndomorphismMatrix" method:

Use the "Homotopy" method:

Use the "Monodromy" method:

Use the "Symbolic" method:

This system has roots, which is strictly less than the bound of provided by the Bernstein-Khovanskii-Kushnirenko theorem:

The "Homotopy" method, used by default, returns multiple copies of some of the roots:

Remove the multiple copies:

The "Monodromy" method runs faster here and does not produce multiple copies of roots:

The "Monodromy" method returns finitely many solutions of transcendental systems:

Use the "Symbolic" method to obtain all solutions:

The Method option may also be used to locally set system options from the "NSolveOptions" group:

By default NSolve introduces slicing hyperplanes for underdetermined complex systems:

With Method->{"UseSlicingHyperplanes"->False}, NSolve gives parametric solutions:

VerifySolutions  (1)

NSolve verifies solutions obtained using non-equivalent transformations:

With VerifySolutions->False, NSolve does not verify the solutions:

Some of the solutions returned with VerifySolutions->False are not correct:

This uses a fast numeric test in an attempt to select correct solutions:

In this case the simple numeric verification gives the correct solution set:

WorkingPrecision  (1)

By default, NSolve finds solutions of exact equations using machine-precision computations:

This computes the solutions using 50-digit precision:

Applications  (17)

Geometry  (11)

Find intersection points of a circle and a parabola:

Find the intersection of InfiniteLine[{0,0},{1,1}] and InfiniteLine[{{0,1},{1,0}}]:

Plot it:

Find the intersections of InfiniteLine[{0,0},{1,1}] and Circle[{0,0},1]:

Plot it:

Find all pairwise intersections between five random lines:

Use BooleanCountingFunction to express that exactly two conditions are true:

Plot it:

Find the pairwise intersections of the circles Circle[{1/3 Cos[k 2π/5],1/3 Sin[k 2π/5]}] for k=0,,4:

Plot it:

Find the intersection of InfiniteLine[{{-1,1,1},{1,1,1}}] and InfinitePlane[{{2,0,0},{0,2,0},{0,0,2}}]:

Plot it:

Find the intersections of InfiniteLine[{{-1,1,1},{1,1,1}}] and Sphere[{0,0,0},3]:

Plot it:

Find the intersections of InfiniteLine[{{-1,1/3,1/2},{1,1/3,1/2}}] and the boundary of Tetrahedron[{{0,0,0},{1,0,0},{0,1,0},{0,0,1}}]:

Plot it:

Find the intersection for three random planes:

Plot it:

Find the intersections of the spheres Sphere[{1/3 Cos[k 2π/3],1/3 Sin[k 2π/3],0}] for k=0,1,2:

Plot it:

Find all the intersections of exactly three planes among 10 random planes:

Use BooleanCountingFunction to find the condition of exactly three things being true:

Plot it:

Chemistry  (1)

A polynomial system for the equilibria of a certain chemical reaction network:

Since the variables represent chemical species quantities, we are interested in real-valued solutions with all components nonnegative::

Find the solutions:

The apparent multiplicity is an artifact of the Automatic method, which tends to be fast but can sometimes overstate multiplicity:

Mechanics  (3)

Direct kinematics of a Gough-Stewart parallel 6-degree of freedom platform:

This solution set claims multiple solutions; remove the multiple copies:

A different method does not produce multiple copies of solutions:

Set up an overdetermined system of six equations in four variables that arises from a camera pose estimation procedure:

Use the first four polynomials so the subsystem will be exactly determined:

For each solution the first four residuals from plugging in a solution are small whereas the last two are non-negligible:

Now polish each solution by using it as a starting point for minimizing the sum of squares of residuals:

A system of equations for static equilibria of a weight suspended by two massless cables in a plane:

Each real-valued solution corresponds to a distinct equilibrium position, and there are six such:

Economics  (1)

A reduced 8-dimensional system arising in economics; we use a non-default method to get better accuracy:

Find the real-valued solutions:

Difference Equations  (1)

A nonlinear system of polynomial difference equations:

RSolve cannot find an analytic form for the solution:

Set up a polynomial system to find the asymptotic values:

Solve it and give asymptotic possible real asymptotic values (they depend on initial conditions):

Properties & Relations  (8)

Solutions approximately satisfy the equations:

Solutions are given as replacement rules and can be directly used for substitution:

NSolve uses {} to represent the empty or no solution:

NSolve uses {{}} to represent the universal solution or that all points satisfy the equations:

For univariate polynomial equations, NSolve repeats solutions according to their multiplicity:

Find solutions over specified domains:

NSolve represents solutions in terms of replacement rules:

NSolveValues gives values of the solutions:

NSolve is a global equation solver:

FindRoot is a local equation solver:

NSolve gives approximate results:

Use Solve to get exact solutions:

Use FindInstance to get exact solution instances:

Use NDSolve to solve differential equations numerically:

Possible Issues  (7)

Solutions obtained with machine-precision numeric computations may not be accurate:

With higher WorkingPrecision more accurate results are produced:

Approximate solutions may not satisfy the equations due to numeric errors:

The equations are satisfied up to a certain tolerance:

Using higher WorkingPrecision will give solutions with smaller tolerance:

If the solutions set of a polynomial system is infinite, NSolve gives its intersection with random hyperplanes:

Use ContourPlot and ContourPlot3D to view the real part of solutions:

NSolve by default can claim multiple solutions when the actual count should be smaller:

Compare to a nondefault method:

Validate against another nondefault method:

Use a particular method to solve a polynomial system with large coefficients:

Use the same method but with higher precision than default:

At machine precision some residuals are not so small:

The solution using higher precision, not surprisingly, gives smaller residuals:

Despite the disparities in residuals, the two solutions agree to all digits of MachinePrecision:

With domain Reals specified, NSolve may not find solutions for which the function is not real-valued in any neighbourhood of the solution:

This gives all real solutions:

NSolve may not give all solutions:

Get solutions:

Neat Examples  (1)

Solve the equation :

Wolfram Research (1991), NSolve, Wolfram Language function, https://reference.wolfram.com/language/ref/NSolve.html (updated 2024).

Text

Wolfram Research (1991), NSolve, Wolfram Language function, https://reference.wolfram.com/language/ref/NSolve.html (updated 2024).

CMS

Wolfram Language. 1991. "NSolve." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/NSolve.html.

APA

Wolfram Language. (1991). NSolve. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NSolve.html

BibTeX

@misc{reference.wolfram_2024_nsolve, author="Wolfram Research", title="{NSolve}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/NSolve.html}", note=[Accessed: 02-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_nsolve, organization={Wolfram Research}, title={NSolve}, year={2024}, url={https://reference.wolfram.com/language/ref/NSolve.html}, note=[Accessed: 02-November-2024 ]}