Problem passing arrays to linsolve( )
- Subject: Problem passing arrays to linsolve( )
- From: Barton Willis
- Date: Tue, 23 Feb 2010 17:08:06 -0600
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
>
>
>--
>____________________________________
>Assad?Ebrahim,?M.Sc.
>London,?England,?U.K.:?+44-078.3294.8332
>http://blog.mathscitech.org
>assad.ebrahim at alum.swarthmore.edu
>
>Director?of?Engineering
>BioSonics,?Inc.
>Seattle,?WA,?U.S.A.
>London,?England,?U.K.
>http://www.biosonicsinc.com
>
>
>_______________________________________________
>Maxima?mailing?list
>Maxima at math.utexas.edu
>http://www.math.utexas.edu/mailman/listinfo/maxima