[Date Index]
[Thread Index]
[Author Index]
Re: Solve or LinearSolve or ...?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg46394] Re: Solve or LinearSolve or ...?
*From*: bobhanlon at aol.com (Bob Hanlon)
*Date*: Mon, 16 Feb 2004 23:43:02 -0500 (EST)
*References*: <c0qitm$k72$1@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
Here's a start:
FindCoefficients[basis_?VectorQ, expr_, f_Symbol] :=
Module[{var, uvar, r, soln, p},
var = Union[Cases[basis, f[__], Infinity]];
uvar=Table[Unique[],{Length[basis]}];
r=Flatten[Solve[Thread[uvar==basis], var]];
soln=CoefficientList[expr /. r, uvar];
p=Join[Table[1,{Length[basis]-1}],{All}];
Table[Last[soln[[Sequence@@(p=RotateRight[p])]]],
{Length[basis]}]];
FindCoefficients[{f[a,a],f[a,b],f[b,a],f[b,b]},
f[a,a]+(1/2)f[b,a],f]
{1, 0, 1/2, 0}
FindCoefficients[{f[a]+f[b],f[a]-f[b]},f[a],f]
{1/2, 1/2}
Bob Hanlon
In article <c0qitm$k72$1 at smc.vnet.net>, semorrison_ at hotmail.com 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],
_f]
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 ...?**
| |