Y = vpasolve(eqns,vars)
numerically solves the system of equations eqns for the variables
vars. This syntax returns a structure array Y
that contains the solutions. The fields in the structure array correspond to the variables
specified by vars. If you do not specify vars,
vpasolve solves for the default variables determined by symvar.

Y = vpasolve(eqns,vars,init_param)
numerically solves the system of equations eqns for the variables
vars using the initial guess or search range
init_param.

[y1,...,yN] = vpasolve(eqns,vars)
numerically solves the system of equations eqns for the variables
vars. This syntax assigns the solutions to the variables
y1,...,yN. If you do not specify vars,
vpasolve solves for the default variables determined by symvar.

___ = vpasolve(___,'Random',true)
uses a random initial guess for finding solutions. Use this input to avoid returning the
same solution repeatedly for nonpolynomial equations. If you specify initial guesses for
all variables, setting 'Random' to true has no
effect.

Assign Solutions to Variables When Solving System of Equations

When solving a system of equations, use multiple output arguments to assign the solutions directly to output variables. The order in which the solver returns the solutions follows the order in which you specify the variables.

Specify Ranges of Solutions

You can specify ranges of solutions of an equation. For example, if you want to restrict your search to only real solutions, you cannot use assumptions because vpasolve ignores assumptions. Instead, specify a search interval. For the following equation, if you do not specify ranges, the numeric solver returns all six solutions of the equation.

The search range can also contain complex numbers, such as [-1, 1+2i]. In this case, vpasolve uses a rectangular search area in the complex plane where -1 specifies the bottom-left corner of the search area and 1+2i specifies the top-right corner of that area.

Find Multiple Solutions for Nonpolynomial Equation

By default, vpasolve returns the same solution on every call. To find more than one solution for nonpolynomial equations, set 'Random' to true. This makes vpasolve use a random initial guess which can lead to different solutions on successive calls.

If 'Random' is not specified, vpasolve returns the same solution on every call.

syms x
f = x-tan(x);
for n = 1:3
S = vpasolve(f,x)
end

S = 0

S = 0

S = 0

When 'Random' is set to true, vpasolve returns a distinct solution on every call.

for n = 1:3
S = vpasolve(f,x,'Random',true)
end

S = -227.76107684764829218924973598808

S = 102.09196646490764333652956578441

S = 61.244730260374400372753016364097

The 'Random' option can be used in conjunction with a search range.

S = vpasolve(f,x,[10 12],'Random',true)

S = 10.904121659428899827148702790189

Input Arguments

eqn — Equation to solvesymbolic equation | symbolic expression

Equation to solve, specified as a symbolic equation or symbolic
expression. A symbolic equation is defined by the relation operator ==. If eqn is
a symbolic expression (without the right side), the solver assumes
that the right side is 0, and solves the equation eqn ==
0.

var — Variable to solve equation forsymbolic variable

Variable to solve equation for, specified as a symbolic variable.
If var is not specified, symvar determines the variables.

System of equations or expressions to be solve, specified as a symbolic vector, matrix, or
array of equations or expressions. These equations or expressions can also be separated
by commas. If an equation is a symbolic expression (without the right side), the solver
assumes that the right side of the equation is 0.

vars — Variables to solve system of equations forsymbolic vector

Variables to solve system of equations for, specified as a symbolic
vector. These variables are specified as a vector or comma-separated
list. If vars is not specified, symvar determines the variables.

Initial guess or search range for a solution, specified as a numeric value, vector,
or matrix with two columns.

If init_param is a number or, in the case of multivariate
equations, a vector of numbers, then the numeric solver uses it as an initial guess. If
init_param is specified as a scalar while the system of equations
is multivariate, then the numeric solver uses the scalar value as an initial guess for
all variables. For an example, see Find Multiple Solutions by Specifying Initial Guesses.

If init_param is a matrix with two columns, then the two
entries of the rows specify the bounds of an initial guess for the corresponding
variables. To specify an initial guess in a matrix of search ranges, specify both
columns as the initial guess value.

If you specify init_param as a search range [a
b] and the values a,b are complex numbers, then
vpasolve searches for the solutions in the rectangular search
area in the complex plane. Here, a specifies the bottom-left corner
of the rectangular search area, and b specifies the top-right corner
of that area. For an example, see Specify Ranges of Solutions.

To omit a search range for a variable, set the search range for that variable to
[NaN, NaN] in init_param. All other uses of
NaN in init_param will error.

Output Arguments

S — Solutions of univariate equationsymbolic value | symbolic array

Solutions of univariate equation, returned as symbolic value
or symbolic array. The size of a symbolic array corresponds to the
number of the solutions.

Y — Solutions of system of equationsstructure array

Solutions of system of equations, returned as a structure array.
The number of fields in the structure array corresponds to the number
of variables to be solved for.

y1,...,yN — Variables that are assigned solutions of system of equationsarray of numeric variables | array of symbolic variables

Variables that are assigned solutions of system of equations,
returned as an array of numeric or symbolic variables. The number
of output variables or symbolic arrays must equal the number of variables
to be solved for. If you explicitly specify independent variables vars,
then the solver uses the same order to return the solutions. If you
do not specify vars, the toolbox sorts independent
variables alphabetically, and then assigns the solutions for these
variables to the output variables or symbolic arrays.

Tips

For polynomial equations, vpasolve returns all solutions. For
nonpolynomial equations, there is no general method of finding all solutions and
vpasolve returns only one solution by default. To find several
different solutions for nonpolynomial, you can set 'Random' to true
and use vpasolve repeatedly.

When you solve a system of equations with nonunique solutions, the behavior of
vpasolve depends on whether the system is polynomial or
nonpolynomial. If polynomial, vpasolve returns all solutions by
introducing an arbitrary parameter. If nonpolynomial, a single numerical solution is
returned, if it exists.

When you solve a system of rational equations, vpasolve transforms
the rational equations to polynomials by multiplying out the denominators.
vpasolve returns all solutions of the resulting polynomial system,
which also include the roots of the denominators.

vpasolve ignores assumptions set on variables. You can restrict the
returned results to particular ranges by specifying appropriate search ranges using the
argument init_param.

The output variables y1,...,yN do
not specify the variables for which vpasolve solves
equations or systems. If y1,...,yN are the variables
that appear in eqns, that does not guarantee
that vpasolve(eqns) will assign the solutions to y1,...,yN using
the correct order. Thus, for the call [a,b] = vpasolve(eqns),
you might get the solutions for a assigned to b and
vice versa.

To ensure the order of the returned solutions, specify the variables
vars. For example, the call [b,a] =
vpasolve(eqns,[b,a]) assigns the solutions for a assigned
to a and the solutions for b assigned to
b.

You can solve equations symbolically using solve, and then
numerically approximate the results using vpa. Using this approach, you
get numeric approximations of all solutions found by the symbolic solver. However, this
can reduce computational speed since solving symbolically and postprocessing the results
take more time than directly using the numeric solver vpasolve.

Algorithms

When you set 'Random' to true and specify a
search range for a variable, random initial guesses within the search range are chosen
using the internal random number generator (with uniform distribution).

When you set 'Random' to true and do not specify
a search range for a variable, random initial guesses are generated using a Cauchy
distribution with a half-width of 100. This means the initial guesses
are real valued and have a large spread of values on repeated calls.

This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic. By continuing to use this website, you consent to our use of cookies. Please see our Privacy Policy to learn more about cookies and how to change your settings.