Functions and Variables for Equations (Maxima 5.46.0 Manual)

Previous: Equations, Up: Equations [Contents][Index]

### 20.1 Functions and Variables for Equations

System variable: %rnum ¶

  Default value: `0`

  `%rnum` is the counter for the `%r` variables introduced in solutions by `solve` and `algsys`.. The next `%r` variable is numbered `%rnum+1`.

  See also `%rnum_list`.

  Categories: Algebraic equations ·

System variable: %rnum_list ¶

  Default value: `[]`

  `%rnum_list` is the list of variables introduced in solutions by `solve` and `algsys`. `%r` variables are added to `%rnum_list` in the order they are created. This is convenient for doing substitutions into the solution later on.

  See also `%rnum`.

  It’s recommended to use this list rather than doing `concat ('%r, j)`.

      (%i1) solve ([x + y = 3], [x,y]);
      (%o1)              [[x = 3 - %r1, y = %r1]]

      (%i2) %rnum_list;
      (%o2)                       [%r1]

      (%i3) sol : solve ([x + 2*y + 3*z = 4], [x,y,z]);
      (%o3)   [[x = - 2 %r3 - 3 %r2 + 4, y = %r3, z = %r2]]

      (%i4) %rnum_list;
      (%o4)                     [%r2, %r3]

      (%i5) for i : 1 thru length (%rnum_list) do
              sol : subst (t[i], %rnum_list[i], sol)$

      (%i6) sol;
      (%o6)     [[x = - 2 t  - 3 t  + 4, y = t , z = t ]]
                           2      1           2       1

  Categories: Algebraic equations ·

Option variable: algepsilon ¶

  Default value: 10^8

  `algepsilon` is used by `algsys`.

  Categories: Algebraic equations ·

Option variable: algexact ¶

  Default value: `false`

  `algexact` affects the behavior of `algsys` as follows:

  If `algexact` is `true`, `algsys` always calls `solve` and then uses `realroots` on `solve`’s failures.

  If `algexact` is `false`, `solve` is called only if the eliminant was not univariate, or if it was a quadratic or biquadratic.

  Thus `algexact: true` does not guarantee only exact solutions, just that `algsys` will first try as hard as it can to give exact solutions, and only yield approximations when all else fails.

  Categories: Algebraic equations ·

Function: algsys
`algsys` ([expr_1, …, expr_m], [x_1, …, x_n])
`algsys` ([eqn_1, …, eqn_m], [x_1, …, x_n]) ¶

  Solves the simultaneous polynomials expr_1, …, expr_m or polynomial equations eqn_1, …, eqn_m for the variables x_1, …, x_n. An expression expr is equivalent to an equation `expr = 0`. There may be more equations than variables or vice versa.

  `algsys` returns a list of solutions, with each solution given as a list of equations stating values of the variables x_1, …, x_n which satisfy the system of equations. If `algsys` cannot find a solution, an empty list `[]` is returned.

  The symbols `%r1`, `%r2`, …, are introduced as needed to represent arbitrary parameters in the solution; these variables are also appended to the list `%rnum_list`.

  The method is as follows:

  1. First the equations are factored and split into subsystems.
  2. For each subsystem S_i, an equation E and a variable x are selected. The variable is chosen to have lowest nonzero degree. Then the resultant of E and E_j with respect to x is computed for each of the remaining equations E_j in the subsystem S_i. This yields a new subsystem S_i’ in one fewer variables, as x has been eliminated. The process now returns to (1).
  3. Eventually, a subsystem consisting of a single equation is obtained. If the equation is multivariate and no approximations in the form of floating point numbers have been introduced, then `solve` is called to find an exact solution.

     In some cases, `solve` is not be able to find a solution, or if it does the solution may be a very large expression.

     If the equation is univariate and is either linear, quadratic, or biquadratic, then again `solve` is called if no approximations have been introduced. If approximations have been introduced or the equation is not univariate and neither linear, quadratic, or biquadratic, then if the switch `realonly` is `true`, the function `realroots` is called to find the real-valued solutions. If `realonly` is `false`, then `allroots` is called which looks for real and complex-valued solutions.

     If `algsys` produces a solution which has fewer significant digits than required, the user can change the value of `algepsilon` to a higher value.

     If `algexact` is set to `true`, `solve` will always be called.

  4. Finally, the solutions obtained in step (3) are substituted into previous levels and the solution process returns to (1).

  When `algsys` encounters a multivariate equation which contains floating point approximations (usually due to its failing to find exact solutions at an earlier stage), then it does not attempt to apply exact methods to such equations and instead prints the message: "`algsys` cannot solve - system too complicated."

  Interactions with `radcan` can produce large or complicated expressions. In that case, it may be possible to isolate parts of the result with `pickapart` or `reveal`.

  Occasionally, `radcan` may introduce an imaginary unit `%i` into a solution which is actually real-valued.

  Examples:

      (%i1) e1: 2*x*(1 - a1) - 2*(x - 1)*a2;
      (%o1)              2 (1 - a1) x - 2 a2 (x - 1)
      (%i2) e2: a2 - a1;
      (%o2)                        a2 - a1
      (%i3) e3: a1*(-y - x^2 + 1);
                                         2
      (%o3)                   a1 (- y - x  + 1)
      (%i4) e4: a2*(y - (x - 1)^2);
                                             2
      (%o4)                   a2 (y - (x - 1) )
      (%i5) algsys ([e1, e2, e3, e4], [x, y, a1, a2]);
      (%o5) [[x = 0, y = %r1, a1 = 0, a2 = 0],

                                        [x = 1, y = 0, a1 = 1, a2 = 1]]
      (%i6) e1: x^2 - y^2;
                                    2    2
      (%o6)                        x  - y
      (%i7) e2: -1 - y + 2*y^2 - x + x^2;
                               2        2
      (%o7)                 2 y  - y + x  - x - 1
      (%i8) algsys ([e1, e2], [x, y]);
                       1            1
      (%o8) [[x = - -------, y = -------],
                    sqrt(3)      sqrt(3)

              1              1             1        1
      [x = -------, y = - -------], [x = - -, y = - -], [x = 1, y = 1]]
           sqrt(3)        sqrt(3)          3        3

  Categories: Algebraic equations ·

Function: allroots
`allroots` (expr)
`allroots` (eqn) ¶

  Computes numerical approximations of the real and complex roots of the polynomial expr or polynomial equation eqn of one variable.

  The flag `polyfactor` when `true` causes `allroots` to factor the polynomial over the real numbers if the polynomial is real, or over the complex numbers, if the polynomial is complex.

  `allroots` may give inaccurate results in case of multiple roots. If the polynomial is real, `allroots (%i*p)` may yield more accurate approximations than `allroots (p)`, as `allroots` invokes a different algorithm in that case.

  `allroots` rejects non-polynomials. It requires that the numerator after `rat`’ing should be a polynomial, and it requires that the denominator be at most a complex number. As a result of this `allroots` will always return an equivalent (but factored) expression, if `polyfactor` is `true`.

  For complex polynomials an algorithm by Jenkins and Traub is used (Algorithm 419, Comm. ACM, vol. 15, (1972), p. 97). For real polynomials the algorithm used is due to Jenkins (Algorithm 493, ACM TOMS, vol. 1, (1975), p.178).

  Examples:

      (%i1) eqn: (1 + 2*x)^3 = 13.5*(1 + x^5);
                                  3          5
      (%o1)              (2 x + 1)  = 13.5 (x  + 1)
      (%i2) soln: allroots (eqn);
      (%o2) [x = .8296749902129361, x = - 1.015755543828121,

      x = .9659625152196369 %i - .4069597231924075,

      x = - .9659625152196369 %i - .4069597231924075, x = 1.0]
      (%i3) for e in soln
              do (e2: subst (e, eqn), disp (expand (lhs(e2) - rhs(e2))));
                            - 3.5527136788005E-15

                           - 5.32907051820075E-15

               4.44089209850063E-15 %i - 4.88498130835069E-15

              - 4.44089209850063E-15 %i - 4.88498130835069E-15

                             3.5527136788005E-15

      (%o3)                         done
      (%i4) polyfactor: true$
      (%i5) allroots (eqn);
      (%o5) - 13.5 (x - 1.0) (x - .8296749902129361)

                                 2
       (x + 1.015755543828121) (x  + .8139194463848151 x

       + 1.098699797110288)

  Categories: Polynomials · Numerical methods ·

Function: bfallroots
`bfallroots` (expr)
`bfallroots` (eqn) ¶

  Computes numerical approximations of the real and complex roots of the polynomial expr or polynomial equation eqn of one variable.

  In all respects, `bfallroots` is identical to `allroots` except that `bfallroots` computes the roots using bigfloats. See `allroots` for more information.

  Categories: Polynomials · Numerical methods ·

Option variable: backsubst ¶

  Default value: `true`

  When `backsubst` is `false`, prevents back substitution in `linsolve` after the equations have been triangularized. This may be helpful in very big problems where back substitution would cause the generation of extremely large expressions.

      (%i1) eq1 : x + y + z = 6$
      (%i2) eq2 : x - y + z = 2$
      (%i3) eq3 : x + y - z = 0$
      (%i4) backsubst : false$

      (%i5) linsolve ([eq1, eq2, eq3], [x,y,z]);
      (%o5)             [x = z - y, y = 2, z = 3]

      (%i6) backsubst : true$

      (%i7) linsolve ([eq1, eq2, eq3], [x,y,z]);
      (%o7)               [x = 1, y = 2, z = 3]

  Categories: Algebraic equations ·

Option variable: breakup ¶

  Default value: `true`

  When `breakup` is `true`, `solve` expresses solutions of cubic and quartic equations in terms of common subexpressions, which are assigned to intermediate expression labels (`%t1`, `%t2`, etc.). Otherwise, common subexpressions are not identified.

  `breakup: true` has an effect only when `programmode` is `false`.

  Examples:

      (%i1) programmode: false$
      (%i2) breakup: true$
      (%i3) solve (x^3 + x^2 - 1);

                              sqrt(23)    25 1/3
      (%t3)                  (--------- + --)
                              6 sqrt(3)   54
      Solution:

                                            sqrt(3) %i   1
                                            ---------- - -
                      sqrt(3) %i   1            2        2   1
      (%t4)    x = (- ---------- - -) %t3 + -------------- - -
                          2        2            9 %t3        3

                                            sqrt(3) %i   1
                                          - ---------- - -
                    sqrt(3) %i   1              2        2   1
      (%t5)    x = (---------- - -) %t3 + ---------------- - -
                        2        2             9 %t3         3

                                         1     1
      (%t6)                  x = %t3 + ----- - -
                                       9 %t3   3
      (%o6)                    [%t4, %t5, %t6]
      (%i6) breakup: false$
      (%i7) solve (x^3 + x^2 - 1);
      Solution:

                   sqrt(3) %i   1
                   ---------- - -
                       2        2        sqrt(23)    25 1/3
      (%t7) x = --------------------- + (--------- + --)
                   sqrt(23)    25 1/3    6 sqrt(3)   54
                9 (--------- + --)
                   6 sqrt(3)   54

                                                    sqrt(3) %i   1    1
                                                 (- ---------- - -) - -
                                                        2        2    3

                 sqrt(23)    25 1/3  sqrt(3) %i   1
      (%t8) x = (--------- + --)    (---------- - -)
                 6 sqrt(3)   54          2        2

                                                  sqrt(3) %i   1
                                                - ---------- - -
                                                      2        2      1
                                            + --------------------- - -
                                                 sqrt(23)    25 1/3   3
                                              9 (--------- + --)
                                                 6 sqrt(3)   54

                  sqrt(23)    25 1/3             1             1
      (%t9)  x = (--------- + --)    + --------------------- - -
                  6 sqrt(3)   54          sqrt(23)    25 1/3   3
                                       9 (--------- + --)
                                          6 sqrt(3)   54
      (%o9)                    [%t7, %t8, %t9]

  Categories: Algebraic equations ·

Function: dimension
`dimension` (eqn)
`dimension` (eqn_1, …, eqn_n) ¶

  `dimen` is a package for dimensional analysis. `load ("dimen")` loads this package. `demo ("dimen")` displays a short demonstration.

  Categories: Share packages ·

Option variable: dispflag ¶

  Default value: `true`

  If set to `false` within a `block` will inhibit the display of output generated by the solve functions called from within the `block`. Termination of the `block` with a dollar sign, `$`, sets `dispflag` to `false`.

  Categories: Algebraic equations · Display flags and variables ·

Function: funcsolve (eqn, g(t)) ¶

  Returns `[g(t) = ...]` or `[]`, depending on whether or not there exists a rational function `g(t)` satisfying eqn, which must be a first order, linear polynomial in (for this case) `g(t)` and `g(t+1)`

      (%i1) eqn: (n + 1)*f(n) - (n + 3)*f(n + 1)/(n + 1) =
            (n - 1)/(n + 2);
                                  (n + 3) f(n + 1)   n - 1
      (%o1)        (n + 1) f(n) - ---------------- = -----
                                       n + 1         n + 2
      (%i2) funcsolve (eqn, f(n));

      Dependent equations eliminated:  (4 3)
                                         n
      (%o2)                f(n) = ---------------
                                  (n + 1) (n + 2)

  Warning: this is a very rudimentary implementation – many safety checks and obvious generalizations are missing.

  Categories: Algebraic equations ·

Option variable: globalsolve ¶

  Default value: `false`

  When `globalsolve` is `true`, solved-for variables are assigned the solution values found by `linsolve`, and by `solve` when solving two or more linear equations.

  When `globalsolve` is `false`, solutions found by `linsolve` and by `solve` when solving two or more linear equations are expressed as equations, and the solved-for variables are not assigned.

  When solving anything other than two or more linear equations, `solve` ignores `globalsolve`. Other functions which solve equations (e.g., `algsys`) always ignore `globalsolve`.

  Examples:

      (%i1) globalsolve: true$
      (%i2) solve ([x + 3*y = 2, 2*x - y = 5], [x, y]);
      Solution

                                       17
      (%t2)                        x : --
                                       7

                                         1
      (%t3)                        y : - -
                                         7
      (%o3)                     [[%t2, %t3]]
      (%i3) x;
                                     17
      (%o3)                          --
                                     7
      (%i4) y;
                                       1
      (%o4)                          - -
                                       7
      (%i5) globalsolve: false$
      (%i6) kill (x, y)$
      (%i7) solve ([x + 3*y = 2, 2*x - y = 5], [x, y]);
      Solution

                                       17
      (%t7)                        x = --
                                       7

                                         1
      (%t8)                        y = - -
                                         7
      (%o8)                     [[%t7, %t8]]
      (%i8) x;
      (%o8)                           x
      (%i9) y;
      (%o9)                           y

  Categories: Linear equations ·

Function: ieqn (ie, unk, tech, n, guess) ¶

  `inteqn` is a package for solving integral equations. `load ("inteqn")` loads this package.

  ie is the integral equation; unk is the unknown function; tech is the technique to be tried from those given in the lists below; (tech = `first` means: try the first technique which finds a solution; tech = `all` means: try all applicable techniques); n is the maximum number of terms to take for `taylor`, `neumann`, `firstkindseries`, or `fredseries` (it is also the maximum depth of recursion for the differentiation method); guess is the initial guess for `neumann` or `firstkindseries`.

  Two types of equations are considered. A second-kind equation of the following form,

                                 b(x)
                                /
                                [
              p(x) = q(x, p(x), I     w(x, u, p(x), p(u)) du)
                                ]
                                /
                                 a(x)

  and a first-kind equation with the form

                               b(x)
                              /
                              [
                       f(x) = I     w(x, u, p(u)) du
                              ]
                              /
                               a(x)

  The different solution techniques used require particular forms of the expressions q and w. The techniques available are the following:

  Second-kind equations

  - `flfrnk2nd`: For fixed-limit, finite-rank integrands.
  - `vlfrnk`: For variable-limit, finite-rank integrands.
  - `transform`: Laplace transform for convolution types.
  - `fredseries`: Fredholm-Carleman series for linear equations.
  - `tailor`: Taylor series for quasi-linear variable-limit equations.
  - `neumann`: Neumann series for quasi-second kind equations.
  - `collocate`: Collocation using a power series form for p(x) evaluated at equally spaced points.

  First-kind equations

  - `flfrnk1st`: For fixed-limit, finite-rank integrands.
  - `vlfrnk`: For variable-limit, finite-rank integrands.
  - `abel`: For singular integrands
  - `transform`: See above
  - `collocate`: See above
  - `firstkindseries`: Iteration technique similar to neumann series.

  The default values for the 2nd thru 5th parameters in the calling form are:

  unk: `p(x)`, where p is the first function encountered in an integrand which is unknown to Maxima and x is the variable which occurs as an argument to the first occurrence of p found outside of an integral in the case of `secondkind` equations, or is the only other variable besides the variable of integration in `firstkind` equations. If the attempt to search for x fails, the user will be asked to supply the independent variable. tech: `first`. n: 1. guess: `none` which will cause `neumann` and `firstkindseries` to use `f(x)` as an initial guess.

  Examples:

      (%i1) load("inteqn")$

      (%i2) e: p(x) - 1 -x + cos(x) + 'integrate(cos(x-u)*p(u),u,0,x)$

      (%i3) ieqn(e, p(x), 'transform);
      default 4th arg, number of iterations or coll. parms.:  1
      default 5th arg, initial guess:  none

      (%t3)                           [x, transform]
      (%o3)                               [%t3]
      (%i4) e: 2*'integrate(p(x*sin(u)), u, 0, %pi/2) - a*x - b$

      (%i5) ieqn(e, p(x), 'firstkindseries);
      default 4th arg, number of iterations or coll. parms.:  1
      default 5th arg, initial guess:  none

      (%t5)          [2 a x + %pi b, firstkindseries, 1, approximate]
      (%o5)                               [%t5]

  Categories: Integral equations ·

Option variable: ieqnprint ¶

  Default value: `true`

  `ieqnprint` governs the behavior of the result returned by the `ieqn` command. When `ieqnprint` is `false`, the lists returned by the `ieqn` function are of the form

  [solution, technique used, nterms, flag]

  where flag is absent if the solution is exact.

  Otherwise, it is the word `approximate` or `incomplete` corresponding to an inexact or non-closed form solution, respectively. If a series method was used, nterms gives the number of terms taken (which could be less than the n given to `ieqn` if an error prevented generation of further terms).

  Categories: Integral equations ·

Function: lhs (expr) ¶

  Returns the left-hand side (that is, the first argument) of the expression expr, when the operator of expr is one of the relational operators `< <= = # equal notequal >= >`, one of the assignment operators `:= ::= : ::`, or a user-defined binary infix operator, as declared by `infix`.

  When expr is an atom or its operator is something other than the ones listed above, `lhs` returns expr.

  See also `rhs`.

  Examples:

      (%i1) e: aa + bb = cc;
      (%o1)                     bb + aa = cc
      (%i2) lhs (e);
      (%o2)                        bb + aa
      (%i3) rhs (e);
      (%o3)                          cc
      (%i4) [lhs (aa < bb), lhs (aa <= bb), lhs (aa >= bb),
             lhs (aa > bb)];
      (%o4)                   [aa, aa, aa, aa]
      (%i5) [lhs (aa = bb), lhs (aa # bb), lhs (equal (aa, bb)),
             lhs (notequal (aa, bb))];
      (%o5)                   [aa, aa, aa, aa]
      (%i6) e1: '(foo(x) := 2*x);
      (%o6)                     foo(x) := 2 x
      (%i7) e2: '(bar(y) ::= 3*y);
      (%o7)                    bar(y) ::= 3 y
      (%i8) e3: '(x : y);
      (%o8)                         x : y
      (%i9) e4: '(x :: y);
      (%o9)                        x :: y
      (%i10) [lhs (e1), lhs (e2), lhs (e3), lhs (e4)];
      (%o10)               [foo(x), bar(y), x, x]
      (%i11) infix ("][");
      (%o11)                         ][
      (%i12) lhs (aa ][ bb);
      (%o12)                         aa

  Categories: Expressions ·

Function: linsolve ([expr_1, …, expr_m], [x_1, …, x_n]) ¶

  Solves the list of simultaneous linear equations for the list of variables. The expressions must each be polynomials in the variables and may be equations. If the length of the list of variables doesn’t match the number of linearly-independent equations to solve the result will be an empty list.

  When `globalsolve` is `true`, each solved-for variable is bound to its value in the solution of the equations.

  When `backsubst` is `false`, `linsolve` does not carry out back substitution after the equations have been triangularized. This may be necessary in very big problems where back substitution would cause the generation of extremely large expressions.

  When `linsolve_params` is `true`, `linsolve` also generates the `%r` symbols used to represent arbitrary parameters described in the manual under `algsys`. Otherwise, `linsolve` solves an under-determined system of equations with some variables expressed in terms of others.

  When `programmode` is `false`, `linsolve` displays the solution with intermediate expression (`%t`) labels, and returns the list of labels.

  See also `algsys`, `eliminate`. and `solve`.

  Examples:

      (%i1) e1: x + z = y;
      (%o1)                       z + x = y
      (%i2) e2: 2*a*x - y = 2*a^2;
                                             2
      (%o2)                   2 a x - y = 2 a
      (%i3) e3: y - 2*z = 2;
      (%o3)                      y - 2 z = 2
      (%i4) [globalsolve: false, programmode: true];
      (%o4)                     [false, true]
      (%i5) linsolve ([e1, e2, e3], [x, y, z]);
      (%o5)            [x = a + 1, y = 2 a, z = a - 1]
      (%i6) [globalsolve: false, programmode: false];
      (%o6)                    [false, false]
      (%i7) linsolve ([e1, e2, e3], [x, y, z]);
      Solution

      (%t7)                       z = a - 1

      (%t8)                        y = 2 a

      (%t9)                       x = a + 1
      (%o9)                    [%t7, %t8, %t9]
      (%i9) ''%;
      (%o9)            [z = a - 1, y = 2 a, x = a + 1]
      (%i10) [globalsolve: true, programmode: false];
      (%o10)                    [true, false]
      (%i11) linsolve ([e1, e2, e3], [x, y, z]);
      Solution

      (%t11)                      z : a - 1

      (%t12)                       y : 2 a

      (%t13)                      x : a + 1
      (%o13)                 [%t11, %t12, %t13]
      (%i13) ''%;
      (%o13)           [z : a - 1, y : 2 a, x : a + 1]
      (%i14) [x, y, z];
      (%o14)                 [a + 1, 2 a, a - 1]
      (%i15) [globalsolve: true, programmode: true];
      (%o15)                    [true, true]
      (%i16) linsolve ([e1, e2, e3], '[x, y, z]);
      (%o16)           [x : a + 1, y : 2 a, z : a - 1]
      (%i17) [x, y, z];
      (%o17)                 [a + 1, 2 a, a - 1]

  Categories: Linear equations ·

Option variable: linsolvewarn ¶

  Default value: `true`

  When `linsolvewarn` is `true`, `linsolve` prints a message "Dependent equations eliminated".

  Categories: Linear equations ·

Option variable: linsolve_params ¶

  Default value: `true`

  When `linsolve_params` is `true`, `linsolve` also generates the `%r` symbols used to represent arbitrary parameters described in the manual under `algsys`. Otherwise, `linsolve` solves an under-determined system of equations with some variables expressed in terms of others.

  Categories: Linear equations ·

System variable: multiplicities ¶

  Default value: `not_set_yet`

  `multiplicities` is set to a list of the multiplicities of the individual solutions returned by `solve` or `realroots`.

  Categories: Algebraic equations · Polynomials ·

Function: nroots (p, low, high) ¶

  Returns the number of real roots of the real univariate polynomial p in the half-open interval `(low, high]`. The endpoints of the interval may be `minf` or `inf`.

  `nroots` uses the method of Sturm sequences.

      (%i1) p: x^10 - 2*x^4 + 1/2$
      (%i2) nroots (p, -6, 9.1);
      (%o2)                           4

  Categories: Polynomials · Numerical methods ·

Function: nthroot (p, n) ¶

  where p is a polynomial with integer coefficients and n is a positive integer returns `q`, a polynomial over the integers, such that `q^n = p` or prints an error message indicating that p is not a perfect nth power. This routine is much faster than `factor` or even `sqfr`.

  Categories: Polynomials ·

Option variable: polyfactor ¶

  Default value: `false`

  The option variable `polyfactor` when `true` causes `allroots` and `bfallroots` to factor the polynomial over the real numbers if the polynomial is real, or over the complex numbers, if the polynomial is complex.

  See `allroots` for an example.

  Categories: Polynomials · Numerical methods ·

Option variable: programmode ¶

  Default value: `true`

  When `programmode` is `true`, `solve`, `realroots`, `allroots`, and `linsolve` return solutions as elements in a list. (Except when `backsubst` is set to `false`, in which case `programmode: false` is assumed.)

  When `programmode` is `false`, `solve`, etc. create intermediate expression labels `%t1`, `%t2`, etc., and assign the solutions to them.

  Categories: Algebraic equations · Polynomials ·

Option variable: realonly ¶

  Default value: `false`

  When `realonly` is `true`, `algsys` returns only those solutions which are free of `%i`.

  Categories: Algebraic equations ·

Function: realroots
`realroots` (expr, bound)
`realroots` (eqn, bound)
`realroots` (expr)
`realroots` (eqn) ¶

  Computes rational approximations of the real roots of the polynomial expr or polynomial equation eqn of one variable, to within a tolerance of bound. Coefficients of expr or eqn must be literal numbers; symbol constants such as `%pi` are rejected.

  `realroots` assigns the multiplicities of the roots it finds to the global variable `multiplicities`.

  `realroots` constructs a Sturm sequence to bracket each root, and then applies bisection to refine the approximations. All coefficients are converted to rational equivalents before searching for roots, and computations are carried out by exact rational arithmetic. Even if some coefficients are floating-point numbers, the results are rational (unless coerced to floats by the `float` or `numer` flags).

  When bound is less than 1, all integer roots are found exactly. When bound is unspecified, it is assumed equal to the global variable `rootsepsilon`.

  When the global variable `programmode` is `true`, `realroots` returns a list of the form `[x = x_1, x = x_2, ...]`. When `programmode` is `false`, `realroots` creates intermediate expression labels `%t1`, `%t2`, …, assigns the results to them, and returns the list of labels.

  Examples:

      (%i1) realroots (-1 - x + x^5, 5e-6);
                                     612003
      (%o1)                     [x = ------]
                                     524288
      (%i2) ev (%[1], float);
      (%o2)                 x = 1.167303085327148
      (%i3) ev (-1 - x + x^5, %);
      (%o3)                - 7.396496210176905E-6

      (%i1) realroots (expand ((1 - x)^5 * (2 - x)^3 * (3 - x)), 1e-20);
      (%o1)                 [x = 1, x = 2, x = 3]
      (%i2) multiplicities;
      (%o2)                       [5, 3, 1]

  Categories: Polynomials · Numerical methods ·

Function: rhs (expr) ¶

  Returns the right-hand side (that is, the second argument) of the expression expr, when the operator of expr is one of the relational operators `< <= = # equal notequal >= >`, one of the assignment operators `:= ::= : ::`, or a user-defined binary infix operator, as declared by `infix`.

  When expr is an atom or its operator is something other than the ones listed above, `rhs` returns 0.

  See also `lhs`.

  Examples:

      (%i1) e: aa + bb = cc;
      (%o1)                     bb + aa = cc
      (%i2) lhs (e);
      (%o2)                        bb + aa
      (%i3) rhs (e);
      (%o3)                          cc
      (%i4) [rhs (aa < bb), rhs (aa <= bb), rhs (aa >= bb),
             rhs (aa > bb)];
      (%o4)                   [bb, bb, bb, bb]

      (%i5) [rhs (aa = bb), rhs (aa # bb), rhs (equal (aa, bb)),
             rhs (notequal (aa, bb))];

      (%o5)                   [bb, bb, bb, bb]
      (%i6) e1: '(foo(x) := 2*x);
      (%o6)                     foo(x) := 2 x
      (%i7) e2: '(bar(y) ::= 3*y);
      (%o7)                    bar(y) ::= 3 y
      (%i8) e3: '(x : y);
      (%o8)                         x : y
      (%i9) e4: '(x :: y);
      (%o9)                        x :: y
      (%i10) [rhs (e1), rhs (e2), rhs (e3), rhs (e4)];
      (%o10)                  [2 x, 3 y, y, y]
      (%i11) infix ("][");
      (%o11)                         ][
      (%i12) rhs (aa ][ bb);
      (%o12)                         bb

  Categories: Expressions ·

Option variable: rootsconmode ¶

  Default value: `true`

  `rootsconmode` governs the behavior of the `rootscontract` command. See `rootscontract` for details.

  Categories: Expressions · Simplification flags and variables ·

Function: rootscontract (expr) ¶

  Converts products of roots into roots of products. For example, `rootscontract (sqrt(x)*y^(3/2))` yields `sqrt(x*y^3)`.

  When `radexpand` is `true` and `domain` is `real`, `rootscontract` converts `abs` into `sqrt`, e.g., `rootscontract (abs(x)*sqrt(y))` yields `sqrt(x^2*y)`.

  There is an option `rootsconmode` affecting `rootscontract` as follows:

      Problem            Value of        Result of applying
                        rootsconmode        rootscontract

      x^(1/2)*y^(3/2)      false          (x*y^3)^(1/2)
      x^(1/2)*y^(1/4)      false          x^(1/2)*y^(1/4)
      x^(1/2)*y^(1/4)      true           (x*y^(1/2))^(1/2)
      x^(1/2)*y^(1/3)      true           x^(1/2)*y^(1/3)
      x^(1/2)*y^(1/4)      all            (x^2*y)^(1/4)
      x^(1/2)*y^(1/3)      all            (x^3*y^2)^(1/6)

  When `rootsconmode` is `false`, `rootscontract` contracts only with respect to rational number exponents whose denominators are the same. The key to the `rootsconmode: true` examples is simply that 2 divides into 4 but not into 3. `rootsconmode: all` involves taking the least common multiple of the denominators of the exponents.

  `rootscontract` uses `ratsimp` in a manner similar to `logcontract`.

  Examples:

      (%i1) rootsconmode: false$
      (%i2) rootscontract (x^(1/2)*y^(3/2));
                                         3
      (%o2)                      sqrt(x y )
      (%i3) rootscontract (x^(1/2)*y^(1/4));
                                         1/4
      (%o3)                     sqrt(x) y
      (%i4) rootsconmode: true$
      (%i5) rootscontract (x^(1/2)*y^(1/4));
      (%o5)                    sqrt(x sqrt(y))
      (%i6) rootscontract (x^(1/2)*y^(1/3));
                                         1/3
      (%o6)                     sqrt(x) y
      (%i7) rootsconmode: all$
      (%i8) rootscontract (x^(1/2)*y^(1/4));
                                    2   1/4
      (%o8)                       (x  y)
      (%i9) rootscontract (x^(1/2)*y^(1/3));
                                   3  2 1/6
      (%o9)                      (x  y )
      (%i10) rootsconmode: false$
      (%i11) rootscontract (sqrt(sqrt(x) + sqrt(1 + x))
                          *sqrt(sqrt(1 + x) - sqrt(x)));
      (%o11)                          1
      (%i12) rootsconmode: true$
      (%i13) rootscontract (sqrt(5+sqrt(5)) - 5^(1/4)*sqrt(1+sqrt(5)));
      (%o13)                          0

  Categories: Simplification functions ·

Option variable: rootsepsilon ¶

  Default value: 1.0e-7

  `rootsepsilon` is the tolerance which establishes the confidence interval for the roots found by the `realroots` function.

  Categories: Polynomials · Numerical methods ·

Function: solve
`solve` (expr, x)
`solve` (expr)
`solve` ([eqn_1, …, eqn_n], [x_1, …, x_n]) ¶

  Solves the algebraic equation expr for the variable x and returns a list of solution equations in x. If expr is not an equation, the equation `expr = 0` is assumed in its place. x may be a function (e.g. `f(x)`), or other non-atomic expression except a sum or product. x may be omitted if expr contains only one variable. expr may be a rational expression, and may contain trigonometric functions, exponentials, etc.

  The following method is used:

  Let E be the expression and X be the variable. If E is linear in X then it is trivially solved for X. Otherwise if E is of the form `A*X^N + B` then the result is `(-B/A)^1/N)` times the `N`’th roots of unity.

  If E is not linear in X then the gcd of the exponents of X in E (say N) is divided into the exponents and the multiplicity of the roots is multiplied by N. Then `solve` is called again on the result. If E factors then `solve` is called on each of the factors. Finally `solve` will use the quadratic, cubic, or quartic formulas where necessary.

  In the case where E is a polynomial in some function of the variable to be solved for, say `F(X)`, then it is first solved for `F(X)` (call the result C), then the equation `F(X)=C` can be solved for X provided the inverse of the function F is known.

  `breakup` if `false` will cause `solve` to express the solutions of cubic or quartic equations as single expressions rather than as made up of several common subexpressions which is the default.

  `multiplicities` - will be set to a list of the multiplicities of the individual solutions returned by `solve`, `realroots`, or `allroots`. Try `apropos (solve)` for the switches which affect `solve`. `describe` may then by used on the individual switch names if their purpose is not clear.

  `solve ([eqn_1, ..., eqn_n], [x_1, ..., x_n])` solves a system of simultaneous (linear or non-linear) polynomial equations by calling `linsolve` or `algsys` and returns a list of the solution lists in the variables. In the case of `linsolve` this list would contain a single list of solutions. It takes two lists as arguments. The first list represents the equations to be solved; the second list is a list of the unknowns to be determined. If the total number of variables in the equations is equal to the number of equations, the second argument-list may be omitted.

  When `programmode` is `false`, `solve` displays solutions with intermediate expression (`%t`) labels, and returns the list of labels.

  When `globalsolve` is `true` and the problem is to solve two or more linear equations, each solved-for variable is bound to its value in the solution of the equations.

  Examples:

      (%i1) solve (asin (cos (3*x))*(f(x) - 1), x);

      solve: using arc-trig functions to get a solution.
      Some solutions will be lost.
                                  %pi
      (%o1)                  [x = ---, f(x) = 1]
                                   6
      (%i2) ev (solve (5^f(x) = 125, f(x)), solveradcan);
                                      log(125)
      (%o2)                   [f(x) = --------]
                                       log(5)
      (%i3) [4*x^2 - y^2 = 12, x*y - x = 2];
                            2    2
      (%o3)             [4 x  - y  = 12, x y - x = 2]

      (%i4) solve (%, [x, y]);
      (%o4) [[x = 2, y = 2], [x = .5202594388652008 %i
       - .1331240357358706, y = .07678378523787788
       - 3.608003221870287 %i], [x = - .5202594388652008 %i
       - .1331240357358706, y = 3.608003221870287 %i
       + .07678378523787788], [x = - 1.733751846381093,
      y = - .1535675710019696]]

      (%i5) solve (1 + a*x + x^3, x);

                                             3
                    sqrt(3) %i   1   sqrt(4 a  + 27)   1 1/3
      (%o5) [x = (- ---------- - -) (--------------- - -)
                        2        2      6 sqrt(3)      2

              sqrt(3) %i   1
             (---------- - -) a
                  2        2
       - --------------------------, x =
                    3
            sqrt(4 a  + 27)   1 1/3
         3 (--------------- - -)
               6 sqrt(3)      2

                                3
       sqrt(3) %i   1   sqrt(4 a  + 27)   1 1/3
      (---------- - -) (--------------- - -)
           2        2      6 sqrt(3)      2

               sqrt(3) %i   1
            (- ---------- - -) a
                   2        2
       - --------------------------, x =
                    3
            sqrt(4 a  + 27)   1 1/3
         3 (--------------- - -)
               6 sqrt(3)      2

               3
       sqrt(4 a  + 27)   1 1/3               a
      (--------------- - -)    - --------------------------]
          6 sqrt(3)      2                  3
                                    sqrt(4 a  + 27)   1 1/3
                                 3 (--------------- - -)
                                       6 sqrt(3)      2
      (%i6) solve (x^3 - 1);
                   sqrt(3) %i - 1        sqrt(3) %i + 1
      (%o6)   [x = --------------, x = - --------------, x = 1]
                         2                     2
      (%i7) solve (x^6 - 1);
                 sqrt(3) %i + 1      sqrt(3) %i - 1
      (%o7) [x = --------------, x = --------------, x = - 1,
                       2                   2

                           sqrt(3) %i + 1        sqrt(3) %i - 1
                     x = - --------------, x = - --------------, x = 1]
                                 2                     2
      (%i8) ev (x^6 - 1, %[1]);

                                            6
                            (sqrt(3) %i + 1)
      (%o8)                 ----------------- - 1
                                   64

      (%i9) expand (%);
      (%o9)                           0
      (%i10) x^2 - 1;
                                    2
      (%o10)                       x  - 1
      (%i11) solve (%, x);
      (%o11)                  [x = - 1, x = 1]
      (%i12) ev (%th(2), %[1]);
      (%o12)                          0

  The symbols `%r` are used to denote arbitrary constants in a solution.

      (%i1) solve([x+y=1,2*x+2*y=2],[x,y]);

      solve: dependent equations eliminated: (2)
      (%o1)                      [[x = 1 - %r1, y = %r1]]

  See `algsys` and `%rnum_list` for more information.

  Categories: Algebraic equations ·

Option variable: solvedecomposes ¶

  Default value: `true`

  When `solvedecomposes` is `true`, `solve` calls `polydecomp` if asked to solve polynomials.

  Categories: Algebraic equations ·

Option variable: solveexplicit ¶

  Default value: `false`

  When `solveexplicit` is `true`, inhibits `solve` from returning implicit solutions, that is, solutions of the form `F(x) = 0` where `F` is some function.

  Categories: Algebraic equations ·

Option variable: solvefactors ¶

  Default value: `true`

  When `solvefactors` is `false`, `solve` does not try to factor the expression. The `false` setting may be desired in some cases where factoring is not necessary.

  Categories: Algebraic equations ·

Option variable: solvenullwarn ¶

  Default value: `true`

  When `solvenullwarn` is `true`, `solve` prints a warning message if called with either a null equation list or a null variable list. For example, `solve ([], [])` would print two warning messages and return `[]`.

  Categories: Algebraic equations ·

Option variable: solveradcan ¶

  Default value: `false`

  When `solveradcan` is `true`, `solve` calls `radcan` which makes `solve` slower but will allow certain problems containing exponentials and logarithms to be solved.

  Categories: Algebraic equations ·

Option variable: solvetrigwarn ¶

  Default value: `true`

  When `solvetrigwarn` is `true`, `solve` may print a message saying that it is using inverse trigonometric functions to solve the equation, and thereby losing solutions.

  Categories: Algebraic equations ·

Previous: Equations, Up: Equations [Contents][Index]