Parameters in MAXIMA Polynomials

Introduction

Parameters in polynomials

I recently had to evaluate some Padé approximants for a hypergeometric function, and used maxima as a tool. (Don't worry if you're unfamiliar with numerical methods for higher transcendetal functions; it's just a way of approximating them with the ratio of two polynomials.) It's important to be sure the polynomial in the denominator doesn't pass through zero in the useful range of its independent variable.

If there were only one independent variable in these functions, the usual maxima operations on polynomials are well documented in the Manual, and would have been easy to use. But the functions I needed have one or more parameters in addition to numerical coefficients and the usual argument; and these parameters are just additional variables to maxima.

When I used the pade function to convert a power series to a ratio of polynomials, powers of the parameters were added to the numerical coefficients; so I had to learn how to handle them. Fortunately, maxima has a way to treat a "variable" as a sort of constant: inhibit evaluation by single-quoting a name.

A simple example

Off to a bad start

The lowest-order approximant I tried had the denominator
             ((p-1.d0)*x-2.d0)
so I entered it in a maxima session as
        (%i1)   den:   ((p-1.d0)*x-2.d0);
and maxima returned
        (%01)          (p - 1.0) x - 2.0
— but this was NOT what I should have done, because (a) it leaves the parameter p as an unspecified variable, and (b) it shifts the numerical calculations from exact integer arithmetic to unreliable floating-point numbers.

Consequently, whenever p is mentioned in later input lines, it is just a symbol. Then I'd have to specify its value every time I wanted a numerical answer. (This can be done, but it's inconvenient.)

If I really wanted a general solution for x that carried p along as a parameter, I could use the solve function:

        (%i2)   solve (den,x);
which gives the one-element list
                                         2
(%o5)                             [x = -----]
                                       p - 1
but then I still would need to evaluate the right side of this equation for some numerical values of p. For example, to see the value of x for p = 5, i'd need to tell maxima
            ev(solve(den,x), p:5);
which sets the value of p for just that input line. Further manipulations would require adding that condition to subsequent statements.

A better way

What I should  have done is this:

First, make the parameter p temporarily immune to evaluation, by prefixing it with a single-quote mark. And write the numerical values as integers, instead of floating-point numbers:

        (%i1)   den:   (('p-1)*x-2);
maxima responds:
        (%o1)           (p - 1) x - 2
Next, set p:
        (%i2)    p:5;
        (%o2)                5
Now solve for x:
        (%i3) ans: ev(solve(den,x));
                                         1
        (%o3)                       [x = -]
                                         2
The solution is a one-element list; its single element is an equation. And this time, the numerical value of x is its right-hand side. At this point, we can extract the value of x with the command
              rhs(ans[1]);
which prints the right side of the equation.

Additional considerations

From some trial values of the approximants, I had noticed that each one was accurate for small values of x, but became unreliable when the product x*p became too large, regardless of the value of p itself, as long as p was larger than 1. As the values of x of interest to me are all small, and the values of p are all large, the biggest term in each of the denominators is the product x*p.

So it's more informative to examine this product, rather than just x, for the various approximants. It's infinite for p = 1, and approaches a limit of 2.0 as p → ∞. As all the cases of practical interest have very small values of the p*x product, they are far from the dangerous region.

 

Copyright © 2024, 2025 Andrew T. Young


Back to the . . .
MAXIMA Introduction page

or the very basic Maxima page

or the website overview page