(This question comes from the last input of Converting Equations to Sparse Arrays in Wolfram Documentation.)
I want to get this (by extensible code):
s0 + s1.{x,y} + s2.{x,y}.{x,y} + s3.{x,y}.{x,y}.{x,y}
But this is my failed trial:
In:
Symbol["s" <> ToString[#]] & /@ Range[0, 3] (*Focus below:*) NestList[HoldForm@Dot[#, {x, y}] &, {x, y}, 2]~Prepend~1 Inner[Times, %%, %, Plus]~Collect~{x, y}
Out:
{s0, s1, s2, s3} {1,{x,y},{x,y}.{x,y},({x,y}.{x,y}).{x,y}} {s0+s1 x+s3 ({x,y}.{x,y}).{x,y}+s2 {x,y}.{x,y},s0+s1 y+s3 ({x,y}.{x,y}).{x,y}+s2 {x,y}.{x,y}}
Problems
-
Parentheses are redundant.
-
I don’t know how to apply
MatrixPower
to achieve that, since the documentation says “MatrixPower works only on square matrices.”
Thanks for help!