Raul Miller wrote:
> Are you talking about something like this?
>
> NB. x + y + 2xy -x^3
> example=: 0&{ + 1&{ + (2 * 0&{ * 1&{) - 3 ^~ 0&{
>
> NB. matrix of coefficients
> NB. dimension 0: powers of x
> NB. dimension 1: powers of y
> mat=: 1 1 2 _1 (1 0;0 1;1 1;3 0)} 4 2$0
>
> mvp=: [ +/^:_@:*"_ _1 [: > [: */"_1&.>/ ] <@(^/ i.)"_1 [EMAIL PROTECTED]
>
>    example i.2 9
> 9 30 49 60 57 34 _15 _96 _215
>    mat mvp i.2 9
> 9 30 49 60 57 34 _15 _96 _215
>

Thanks for your suggestions, Raul.

I have been using the following for 2-variable polynomial evaluation:

NB. Vandermonde matrix
van=:(>@{. */ >@{:)@:((^ [EMAIL PROTECTED])/&.>)@:(<"1@:(],.$@:[))
NB. Multiply by Vandermonde matrix and add
eval=:(+/ @: (+/) @: ([ * van))"_ 1

On your example this gives

   mat eval |: i. 2 9
9 30 49 60 57 34 _15 _96 _215

I have also done it by evaluating rows as regular polynomials, and
then multiplying by powers of x, but this seems less symmetrical.

I am sure there is a slicker method for the Vandermonde matrix (and it
comes up all the time), but I cannot see it.

I am more interested in multiplying polynomials and looking at their
coefficients.  Extending the 1-variable case works well:

ppr=: +//.@(*/)
ppr2=: +//.@(ppr"1/)

  mat ppr2 mat
 0  0 1
 0  2 4
 1  4 4
 0 _2 0
_2 _4 0
 0  0 0
 1  0 0

This gives the matrix square of the polynomial mat.

Best wishes,

John


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to