MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Solve or LinearSolve or ...?

  • To: mathgroup at
  • Subject: [mg46394] Re: Solve or LinearSolve or ...?
  • From: bobhanlon at (Bob Hanlon)
  • Date: Mon, 16 Feb 2004 23:43:02 -0500 (EST)
  • References: <c0qitm$k72$>
  • Sender: owner-wri-mathgroup at

Here's a start:

FindCoefficients[basis_?VectorQ, expr_, f_Symbol] :=
    Module[{var, uvar, r, soln, p},
      var = Union[Cases[basis, f[__], Infinity]];
      r=Flatten[Solve[Thread[uvar==basis], var]];
      soln=CoefficientList[expr /. r, uvar];


{1, 0, 1/2, 0}


{1/2, 1/2}

Bob Hanlon

In article <c0qitm$k72$1 at>, semorrison_ at wrote:

<< I'm trying to write a function to calculate coefficients in a basis;
for example

FindCoefficients[{f[a,a],f[a,b],f[b,a],f[b,b]}, f[a,a]+(1/2)f[b,a],

should produce {1,0,1/2,0}. The third argument there means `assuming
all objects matching _f are linearly independent'. More difficult, it
should produce

FindCoefficients[{f[a]+f[b],f[a]-f[b]},f[a], _f] == {1/2,1/2}.

And finally, it should work with rational functions as coefficients,
not just numbers, and it should run fast enough to be useful with
bases with thousands of elements. :-)

I've spent quite some time trying to write something like this, and
I'm finding it really difficult! I can't seem to use LinearSolve in
any way -- it seems to trip up when I use rational functions as
coefficients. I've been trying to work around Solve, but the only
things that work are glacial in pace!

Any ideas or suggestions? 

  • Prev by Date: Re: No Output, No Error
  • Next by Date: RE: Understanding Flatten
  • Previous by thread: Re: how to read this data file in mathematica?
  • Next by thread: Re: Solve or LinearSolve or ...?