## `numeric::solve` -- numerical solution of equations (the float attribute of solve)

#### Introduction

`numeric::solve` computes numerical solutions of equations.

#### Call(s)

`numeric::solve(eqs, <, vars> <, Options>)`
`float(hold(solve)(eqs, <, vars> <, Options>))`

`float(freeze(solve)(eqs, <, vars> <, Options>))`

#### Parameters

`eqs` | - | an equation, a list of equations, or a set of equations. Also arithmetical expressions are accepted and interpreted as homogeneous equations.

#### Options

``vars`` | - | an unknown, a list of unknowns or a set of unknowns. Unknowns may be identifiers or indexed identifiers. Also equations of the form `x=a` or `x=a..b` are accepted wherever an unknown `x` is expected. This way starting points and search ranges are specified for the numerical search. They must be numerical, infinite search ranges are accepted.
``Options`` | - | a combination of Multiple, FixedPrecision, SquareFree, Factor, RestrictedSearch, or Random
`Multiple` | - | only to be used if `eqs` is a polynomial equation or a system of polynomial equations. With this option, information on the multiplicity of degenerate polynomial roots is returned.
`FixedPrecision` | - | only to be used if `eqs` is a single univariate polynomial. It launches a quick numerical search with fixed internal precision.
`SquareFree` | - | only to be used if `eqs` is a single univariate polynomial. Symbolic square free factorization is applied, before the numerical search starts.
`Factor` | - | only to be used if `eqs` is a single univariate polynomial. Symbolic factorization is applied, before the numerical search starts.
`RestrictedSearch` | - | only to be used for non-polynomial equations. The numerical search is restricted to the search ranges specified in `vars`.
`Random` | - | only to be used for non-polynomial equations. With this option, several calls to `numeric::solve` may lead to different solutions of the equation(s).

#### Returns

a set of numerical solutions. With the option Multiple, a set of domain type `Dom::Multiset` is returned.

#### Side Effects

The function is sensitive to the environment variable `DIGITS`, which determines the numerical working precision.

#### Related Functions

`linsolve`, `numeric::fsolve`, `numeric::linsolve`, `numeric::polyroots`, `numeric::polysysroots`, `numeric::realroot`, `numeric::realroots`, `polylib::realroots`, `solve`

#### Details

- The call `numeric::solve(arguments)` is equivalent to calling the float attribute of `solve` by `float``(``hold``(``solve``)(arguments))` or alternatively by `float``(``freeze``(``solve``)(arguments))`
- `numeric::solve` is a simple interface function unifying the functionality of the numerical solvers `numeric::fsolve`, `numeric::polyroots` and `numeric::polysysroots`. The return format of these routines is changed to make it consistent with the return values of the symbolic solver `solve`.
- You may call the specialized numerical solvers directly. However, note the return types specific to each of these solvers.
- `numeric::solve` classifies the equations as follows:
  a)
    If `eqs` is a single univariate polynomial equation, then it is directly passed to `numeric::polyroots`. Cf. example 2. The roots are returned as a set or as a `Dom::Multiset`, if Multiple is used.
  b)
    If `eqs` is a multivariate polynomial equation or a list or set containing such an equation, then the equations and the appropriate optional arguments are passed to `numeric::polysysroots`. Cf. example 3. The roots are returned as a set or as a `Dom::Multiset`, if Multiple is used.
  c)
    If `eqs` is a non-polynomial equation or a set or list containing such an equation, then then the equations and the appropriate optional arguments are passed to the numerical solver `numeric::fsolve`.

    Note that for non-polynomial equations there must not be more equations than unknowns!

    Using Multiple for non-polynomial equations leads to an error!

    A single numerical root is returned. Cf. example 4.

- For convenience, also polynomials of domain type `DOM_POLY` are accepted, wherever an equation is expected.

- In contrast to the symbolic solver `solve`, the numerical solver does not react to properties of identifiers set via `assume`.

#### Option: `vars`

- If the user does not specify indeterminates to be solved for, then the indeterminates are internally chosen by `numeric::indets``(eqs)`.
- Starting points such as `x=a` or search ranges such as `x=a..b` specified in `vars` are ignored, if `eqs` is a polynomial equation or a system of polynomial equations.

#### Option: Multiple

- This option may only be used when solving polynomial equations! It changes the return type from `DOM_SET` to `Dom::Multiset`.

#### Option: FixedPrecision

- This option only has an effect if `eqs` is a single univariate polynomial equation. It is passed to `numeric::polyroots`, which uses a numerical search with fixed internal precision. This is fast, but degenerate roots may be returned with a restricted precision. See the help page of `numeric::polyroots` for details.

#### Option: SquareFree

- This option only has an effect if `eqs` is a single univariate polynomial equation. It is passed to `numeric::polyroots`, which preprocesses the polynomial by a symbolic square free factorization. See the help page of `numeric::polyroots` for details.

#### Option: Factor

- This option only has an effect if `eqs` is a single univariate polynomial equation. It is passed to `numeric::polyroots`, which preprocesses the polynomial by a symbolic factorization. See the help page of `numeric::polyroots` for details.

#### Option: RestrictedSearch

- This option only has an effect if `eqs` contains a non-polynomial equation. It is passed to `numeric::fsolve`, which restricts the search to the search range specified in `vars`. See the help page of `numeric::fsolve` for details.
- This option should only be used in conjunction with search ranges.

#### Option: Random

- This option only has an effect if `eqs` contains a non-polynomial equation. It is passed to `numeric::fsolve` which switches to a random search strategy. See the help page of `numeric::fsolve` for details.

#### Example 1

The following three calls are equivalent:

    >> eqs := {x^2 = sin(y), y^2 = cos(x)}:

    >> numeric::solve(eqs, {x, y}),
       float(hold(solve)(eqs, {x, y})),
       float(freeze(solve)(eqs, {x,y}))

          {[y = 0.8116062152, x = 0.8517004887]},

             {[y = 0.8116062152, x = 0.8517004887]},

             {[y = 0.8116062152, x = 0.8517004887]}

    >> delete eqs:

#### Example 2

We demonstrate the root search for univariate polynomials:

    >> numeric::solve(x^6 - PI*x^2 = sin(3), x)

          {-1.339589767, 1.339589767, - 1.322706295 I, - 0.2120113223 I,

             0.2120113223 I, 1.322706295 I}

Polynomials of type `DOM_POLY` can be used as input:

    >> numeric::solve(poly((x - 1/3)^3, [x]), x)

                                  {0.3333333333}

With Multiple, a `Dom::Multiset` is returned, indicating the multiplicity of the root:

    >> numeric::solve(x^3 - x^2 + x/3 -1/27, x, Multiple)

                                {[0.3333333333, 3]}

#### Example 3

We demonstrate the root search for polynomial systems. Note that the symbolic solver `solve` is involved. Symbolic parameters are accepted:

    >> numeric::solve({x^2 + y^2 = 1, x^2 - y^2 = exp(z)}, {x, y})

                                                 1/2
          {[y = - 0.7071067812 (1.0 - 1.0 exp(z))   ,

                                              1/2
             x = - 0.7071067812 (exp(z) + 1.0)   ],

             ...
                                                 1/2
             [y = 0.7071067812 (1.0 - 1.0 exp(z))   ,

                                            1/2
             x = 0.7071067812 (exp(z) + 1.0)   ]}

#### Example 4

We demonstrate the root search for non-polynomial equations.

    >> eq := exp(-x) - 10*x^2:

    >> numeric::solve(eq, x)

                                  {0.2755302947}

Since `numeric::solve` just calls the root finder `numeric::fsolve`, one may also use this routine directly. Note the different output format:

    >> numeric::fsolve(eq, x)

                                [x = 0.2755302947]

The input syntax of `numeric::solve` and `numeric::fsolve` are identical, i.e., starting points, search ranges and options may be used. E.g., another solution of the previous equation is found by a restricted search over the interval [-1,0]:

    >> numeric::solve(eq, x = -1..0, RestrictedSearch)

                                  {-0.3829657727}

The following search for a solution in the entire 2-dimensional plane fails:

    >> eqs := [exp(x) = 2*y^2, sin(y) = y*x^3]:

    >> numeric::solve(eqs, [x, y])

                                       {[]}

Assisted by starting points for the internal search a solution is found:

    >> numeric::solve(eqs, [x = 1, y = 1.5])

                       {[x = 0.9290711315, y = 1.125201325]}

Another solution with negative y is found with an appropriate search range:

    >> numeric::solve(eqs, [x = 1, y = -infinity..0])

                      {[x = 0.9290711314, y = -1.125201325]}

    >> delete eq, eqs:

#### Changes

- new function

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000