Post Reply 
subscripts in CAS?
12-15-2016, 04:53 AM
Post: #4
RE: subscripts in CAS?
What I had in mind was the ability to treat a[k] as you would any other identifier, such as solve([a[1]+a[2]+a[3]=1,a[1]^2+a[3]=2, a[2]-a[3]=3],[a[1],a[2],a[3]])

Perhaps it would be better to just show the application I was working on. The following is a function I wrote for Maxima which calculates the coefficients used for the various polynomial integration rules: Trapezoid Rule (n=1), Simpson's Rule (n=2), Simpson's 3/8 Rule (n=3), etc.

Notice how eqs and coefs are lists of equations and coefficients which are determined at run time. In particular, the linsolve() function uses the coefs list as the list of variables to solve for.

Code:

NewtonCotesWeights(n):=
block ( [a, coefs, eqs, sol, k, i, ret],
    p(x,n):=sum(a[k]*x^k, k, 1, n)+a[0],
    coefs(n):=makelist(a[k],k,0,n),
    eqs(n):=makelist(y[k]=p(k*h,n),k,0,n),
    sol:linsolve(eqs(n),coefs(n)),
    for i: 0 thru n do
      b[i]:=rhs(sol[i+1]),
    ret:factor(integrate(sum(b[k]*x^k, k, 1, n)+b[0],x,0,n*h)),
    for i: 0 thru n do
      kill(b[i]),
    ret
    );

NewtonCotesWeights(3);
(3*(y[3]+3*y[2]+3*y[1]+y[0])*h)/8

I've not been able to figure out how to do this on the Prime. It boils down to being able to treat a subscripted identifier as it would any other identifier.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
subscripts in CAS? - Wes Loewer - 12-12-2016, 06:40 PM
RE: subscripts in CAS? - Han - 12-12-2016, 08:57 PM
RE: subscripts in CAS? - compsystems - 12-13-2016, 02:40 AM
RE: subscripts in CAS? - Wes Loewer - 12-15-2016 04:53 AM
RE: subscripts in CAS? - parisse - 12-15-2016, 07:45 AM
RE: subscripts in CAS? - Wes Loewer - 12-15-2016, 06:40 PM
RE: subscripts in CAS? - compsystems - 12-17-2016, 12:21 PM



User(s) browsing this thread: 1 Guest(s)