Next: Fitting in Mathematica Up: Fitting Previous: A Summary of Fitting

### Fitting in Maple

In Maple things initially proceed in a much the same way as they did in Maxima. And so, we have to define arrays xi, yi, and first:

The syntax of the array command is slightly different from that of Maxima. We will summarise those differences in a table towards the end of this chapter. In short, the command array creates a new array with dimensions given its first argument. The second argument is optional and can be used to initialise the values in an array.

Now we define :

The syntax of sum is nearly the same as in Maxima. The only difference is the way that the range of i is specified. The next step is to evaluate and , equate the partial derivatives to zero and solve the resulting linear equations:

The solve command of Maple is much more powerful than its relative in Maxima, so we don't have to modify equations da = 0 and db = 0 any further. On the other hand, we have to save the result on a list, which we are going to call solutions, because Maple doesn't generate expression labels automatically. Having saved the solution we will then be able to chop it to pieces and make corresponding assignments to a and b.

Observe that at least this time Maxima does a better job of formatting output, although the above looks a lot better when printed on the Maple X11 Worksheet using real Greek letters. The result of calling solve is a list of two equations. solutions[1] returns the first equation, b = ..., and solutions[2] returns the second one, a = .... In order to make the assignments we have to use function rhs, which extracts the right hand side of an equation it is applied to:

and

Maple would make a mess out of the solutions list if you tried,
b := rhs(solutions[1]);

instead of b0 := rhs(solutions[1]), because it would substitute the new value of b into the solutions list at the same time. It is safer to create new variables a0 and b0 while extracting the relevant assignments with rhs.

So far, so good. Now we are going to hit the same bug as we have already found in Maxima. Taking derivatives and returns zero in both cases!

Unfortunately, Maple in this context is even worse than Maxima. Let us look again at a simpler expression

and let us try a Maple equivalent of Maxima's command

that worked so nicely for us in the previous section. Here is what Maple does with this expression:

As you see, Maple steadfastly refuses even to substitute 3 for k, treating the whole expression dy[k] as one unstructured object. We have to request differentiation with respect to y[3] explicitly:

Since we are forced to subject ourselves to such indignities, we can just as well evaluate the sums at the very beginning and differentiate the result explicitly with respect to y3.

And so this is our Maple result for , for n=5 and k=3:

And similarly for for n=5 and k=3:

There is no exact equivalent of Maxima's pickapart command in Maple, so we can't simplify expressions for da0y and db0y, easily, in terms of new, dynamically generated variables.  Maple has some low level utilities for splitting expressions apart and some high level ones, of which you have already encountered rhs. In this case you could also try numer and denom, which would extract  numerator and denominator from both da0y and db0y, but while doing so, they would fully expand the resulting expressions too, making them even less readable and less manageable.

In summary, this is where we've got to stop in Maple. The obtained expressions for a, b, , and are correct (cf. Section 2.1.8), and can be easily compared to results returned by Maxima.

Next: Fitting in Mathematica Up: Fitting Previous: A Summary of Fitting
Zdzislaw Meglicki
2001-02-26