English 中文(简体)
Solving linear systems in Maxima
原标题:

I m trying to write a general solver for a linear system in Maxima using linsolve(eqlist, varlist), but without having to explicitly specify the dimension of the problem.

This works, but fixes the dimension to 3:

linsolve( [ eq[0],eq[1],eq[2] ], [ a[0],a[1],a[2] ])

This doesn t:

solution(p):=(  
  array(eq,p+1), /* creating arrays of length p+1 */
  array(a,p+1),

  for i:0 thru p do (
    eq[i]: sum(binom(j+1,i)*a[j],j,i,p) = binom(p,i)
  ),

  linsolve(eq,a)
)

Any insight on how to get this to work?


Background behind the problem: this linear system arises when solving the finite summation of integer powers, i.e. the sum of finitely many squares, cubes, or general powers p. Although the finite sum of squares is straightforward, the general solution is surprisingly complicated: a discussion can be found here: Finite Summation by Recurrence Relations, Part 2.
最佳回答

Apparently in Maxima, lists and arrays are NOT the same underlying object.

Arrays are more complex and a bit of mess to get working (as suggested in this posting to the Maxima mailing list).

The problem goes away if we stay away from arrays and work with lists instead:

solution(p):= block([a, eq],        /* give subroutine variables local scope */
    v : makelist(a[i], i, 0, p),    /* create list of unknowns (0-indexed) */
   eq : makelist(sum(binom(j+1,i)*a[j],j,i,p) = binom(p,i), i, 0, p),  
                                    /* create list of equations (0-indexed) */
   linsolve(eq, v)
)
问题回答

暂无回答




相关问题
Maths in LaTex table of contents

I am trying to add a table of contents for my LaTex document. The issue I am having is that this line: subsubsection{The expectation of (X^2)} Causes an error in the file that contains the ...

Math Overflow -- Handling Large Numbers

I am having a problem handling large numbers. I need to calculate the log of a very large number. The number is the product of a series of numbers. For example: log(2x3x66x435x444) though my actual ...

Radial plotting algorithm

I have to write an algorithm in AS3.0 that plots the location of points radially. I d like to input a radius and an angle at which the point should be placed. Obviously I remember from geometry ...

Subsequent weighted algorithm for comparison

I have two rows of numbers ... 1) 2 2 1 0 0 1 2) 1.5 1 0 .5 1 2 Each column is compared to each other. Lower values are better. For example Column 1, row 2 s value (1.5) is more ...

热门标签