kernel connection lost with PolynomialInterpolation

Dear all,

I am working with Maple 11 and 12 on an Intel Mac running Leopard, and I am having trouble with a very simple script that keeps telling "kernel connection lost"; see below.

> restart; with(CurveFitting);
> poly2 := proc (x, u) return PolynomialInterpolation(x, u, z) end proc;
proc(x, u) ... end;
> getArrays := proc (left, right) local x, u; x := [seq(h*i, i = left .. right)]; u := [seq(u[i], i = left .. right)]; return x, u end proc;
proc(left, right) ... end;
> x, u := getArrays(-2, 2);
[-2 h, -h, 0, h, 2 h], [u[-2], u[-1], u[0], u[1], u[2]]
> poly2(x, u);

I have tried a wide range of data types, (vectors, arrays, sequences), but to no avail. I also checked the manuals and googled for this error, but found nothing concrete enough to be of use. Am I doing something silly ?

Thanks already for any possible pointer !

Giovanni

acer's picture

not a bug in PolynomialInterpolation

This is not a bug in PolynomialInterpolation. The problem is that you have set up getArrays() to return a list whose elements are self-referencing. Subsequent access of its elements results in an infinite recursion.

> getArrays := proc (left, right)
> local x, u;
>   x := [seq(h*i, i = left .. right)];
>   u := [seq(u[i], i = left .. right)]; # the problem
>   return x, u
> end proc:

> x, u := getArrays(-2, 2);
        x, u := [-2 h, -h, 0, h, 2 h], [u[-2], u[-1], u[0], u[1], u[2]]

> u[1]; # bye bye
Execution stopped: Stack limit reached.

It's the local variable name 'u', inside getArrays(), for which it's not programmed well. The same thing would happen if you did the top-level assignment x,t := getArrays(-2, 2); and then accessed t[1].

Maple can catch and prevent some similar sorts of recusive assignment when done at the top-level. But within a procedure definition, you're much more on your own. Here's the behaviour, if you try it at the top-level,

> u := [seq(u[i], i = -2 .. 2)];
Error, recursive assignment
> u := [u[1], u[2]];
Error, recursive assignment

Compare that with,

> u := [9,17]:
> u := [u[1], u[2]];
                                 u := [9, 17]

Note that the assignment u:=[u[1],u[2]] is not necessarily recursive. It depends on the value of u coming in. If u equals [9,17] then it's fine. If u is unassigned then it's recursive. Maple can tell, at the top-level, how things stand. But when you are defining a procedure Maple cannot tell. It's when the procedure runs that it will be OK or not. So Maple let's you define the procedure as you wish.

So, you'll probably want to change how getArrays works. I can't make a good suggestion without knowing whether you truly want the second output of getArrays to contain escaped local names. Do you want the 'u' inside the second output of getArrays to be the global name u or the name of the (escaped) local of getArrays? Do you truly want getArrays to return lists, or would Arrays be OK?

acer

Thanks; just changing the

Thanks; just changing the internal variable to v instead of u solved it for me...

My main problem arises from the fact that on my machine, apparently, everything that I do wrong generates a "kernel connection lost" instead of the more meaningful "stack limit exceeded" which would already have helped me look into some direction.

Anyway, a great thank you ! You saved me at least a day.

Giovanni

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}