Thanks Barton, your solution is tighter than the one I came up with.
For the archives --
Robert Dodier's post: "arrays are a bit of mess"
(http://www.math.utexas.edu/pipermail/maxima/2008/010002.html) suggests
that arrays and lists are NOT the same underlying object in Maxima, and
that arrays seem to be more complex.
Given that, rewriting using lists:
solution(p):= (
kill(a), kill(eq), /* clear namespace */
a: makelist(concat(a,i),i,1,p+1),
for i:1 thru p+1 do ( /* list of equations */
eq[i]: sum(binom(j,i-1)*a[j],j,i,p+1) = binom(p,i-1)
),
listarray(eq),
linsolve(listarray(eq),a) /* solve (p+1) x (p+1)
lin. system */
)$
FYI - the problem that leads to this linear system is the finite
summation of integer powers, i.e. finite sum of k^2, or k^3, ..., or in
general k^p. Turns out that although obtaining a closed form formula
for the first case is straightforward (is straightforward), obtaining a
general solution is more intricate.
A complete discussion is here:
http://mathscitech.org/articles/finite-summations-2
Cheers, -- this case can be considered closed.
Assad
On 2/23/2010 3:08 PM, Barton Willis wrote:
> Try using lists, not arrays:
>
> solution(p):= block([eq : [], v : []],
> for i:0 thru p do (
> eq : cons (sum(binomial(j+1,i)*a[j],j,i,p) = binomial(p,i), eq),
> v : cons(a[i], v)),
> linsolve(eq,v));
>
> Barton
>
> -----maxima-bounces at math.utexas.edu wrote: -----
>
>
>> I'm trying to use linsolve( ) from within a subroutine in order to code
>> up a solution algorithm that is independent of the dimension of the
>> problem.
>>
>> The desire is to dynamically allocate the equation and variable arrays
>> within the subroutine itself, pass these to linsolve( ) and hopefully
>> get back the results.
>>
>> /* SUBROUTINE IDEA -- INCORRECT SYNTAX */
>> solution(p):=(
>> array(eq,p),
>> array(a,p),
>>
>> for i:0 thru p do (
>> eq[i]: sum(binom(j+1,i)*a[j],j,i,p) = binom(p,i)
>> ),
>>
>> linsolve(eq,a) /* THIS IS WHERE THE PROBLEM LIES */
>> )$
>>
>>
>> Clearly, linsolve( ) doesn't like being passed arrays in this way.
>>
>> If I manually provide the list of elements of the arrays, like below, it
>> works for one particular case, which of course defeats the purpose of
>> having the general subroutine.
>>
>> linsolve([eq[0],eq[1],eq[2]],[a[0],a[1],a[2]])
>> /* UGLY: HAVE TO PASS EACH ELEMENT IN BY HAND */
>>
>> Any insight would be appreciated,
>> Assad
>>