NSolve
NSolve[expr,vars]
attempts to find numerical approximations to the solutions of the system expr of equations or inequalities for the variables vars.
Details and Options
- The system expr can be any logical combination of:
-
lhs==rhs equations lhs!=rhs inequations lhs>rhs or lhs>=rhs inequalities expr∈dom domain specifications {x,y,…}∈reg region 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&&vars∈Reals,vars,Complexes] solves for real values of variables, but function values are allowed to be complex.
- NSolve[…,x∈reg,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 Automatic maximum number of roots returned Method Automatic what method should be used RandomSeeding 1234 the seeding of pseudorandom generators VerifySolutions Automatic whether to verify solutions WorkingPrecision Automatic precision to be used in computations - Possible Method settings include "EndomorphismMatrix", "Homotopy", "Monodromy", and "Symbolic". »
Examples
open allclose allBasic Examples (6)
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:
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:
Systems of Complex Equations in Several Variables (9)
Real Equations in One Variable (11)
Polynomial equations with multiple roots:
Transcendental equations, solvable using inverse functions:
Transcendental equations, solvable using special function zeros:
Transcendental inequalities, solvable using special function zeros:
High-degree sparse polynomial equations:
Algebraic equations involving high-degree radicals:
Equations involving irrational real powers:
Tame elementary function equations:
Systems of Real Equations and Inequalities in Several Variables (9)
Quantified polynomial systems:
Transcendental systems solvable using inverse functions:
Systems exp-log in the first variable and polynomial in the other variables:
Systems elementary and bounded in the first variable and polynomial in the other variables:
Systems holomorphic and bounded in the first variable and polynomial in the other variables:
Generalizations & Extensions (1)
Options (10)
MaxRoots (4)
Method (4)
Solve a square polynomial system using the automatically chosen method:
Use the "EndomorphismMatrix" 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:
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:
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}}]:
Find the intersections of InfiniteLine[{0,0},{1,1}] and Circle[{0,0},1]:
Find all pairwise intersections between five random lines:
Use BooleanCountingFunction to express that exactly two conditions are true:
Find the pairwise intersections of the circles Circle[{1/3 Cos[k 2π/5],1/3 Sin[k 2π/5]}] for k=0,…,4:
Find the intersection of InfiniteLine[{{-1,1,1},{1,1,1}}] and InfinitePlane[{{2,0,0},{0,2,0},{0,0,2}}]:
Find the intersections of InfiniteLine[{{-1,1,1},{1,1,1}}] and Sphere[{0,0,0},3]:
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}}]:
Find the intersection for three random planes:
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:
Find all the intersections of exactly three planes among 10 random planes:
Use BooleanCountingFunction to find the condition of exactly three things being true:
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::
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:
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