[Date Index]
[Thread Index]
[Author Index]
Re: Beginner--[Please Help]How to get coefficient list issued from a Series Command
*To*: mathgroup at smc.vnet.net
*Subject*: [mg70201] Re: Beginner--[Please Help]How to get coefficient list issued from a Series Command
*From*: dimmechan at yahoo.com
*Date*: Sat, 7 Oct 2006 07:07:40 -0400 (EDT)
*References*: <eg2e8k$73m$1@smc.vnet.net><eg4sik$fen$1@smc.vnet.net>
lst = (a[#1] + b[#1]*x + c[#1]*x^2 & ) /@ Range[3]
{a[1] + x*b[1] + x^2*c[1], a[2] + x*b[2] + x^2*c[2], a[3] + x*b[3] +
x^2*c[3]}
selectCoeff[lis_List, x_] := Cases[lis, x[_], Infinity]
(selectCoeff[lst, #1] & ) /@ {a, b, c}
{{a[1], a[2], a[3]}, {b[1], b[2], b[3]}, {c[1], c[2], c[3]}}
Apply[Plus, %, 1]
{a[1] + a[2] + a[3], b[1] + b[2] + b[3], c[1] + c[2] + c[3]}
dimmechan at yahoo.com wrote:
> Hello.
>
> What you need is very easy. But in order to do programming I need to
> modify a little your K list.
> For example the first element of the list, a1+b1 x +c1 x^2 was
> modified to a[1]+b[1]x+c[1]x^2 which
> apart for issues of programming is the proper one since as said you
> deal with power series.
>
> First define the list
>
> lst = (a[#1] + b[#1]*x + c[#1]*x^2 & ) /@ Range[3]
> {a[1] + x*b[1] + x^2*c[1], a[2] + x*b[2] + x^2*c[2], a[3] + x*b[3] +
> x^2*c[3]}
>
> Then use Cases
>
> Cases[lst, a[_], Infinity]
> {a[1], a[2], a[3]}
> Cases[lst, b[_], Infinity]
> {b[1], b[2], b[3]}
> Cases[lst, c[_], Infinity]
> {c[1], c[2], c[3]}
>
> and here is the desired user-defined function
>
> selectCoeff[lis_List, x_] := Cases[lis, x[_], Infinity]
>
> (*check*)
>
> selectCoeff[lst, a]
> {a[1], a[2], a[3]}
>
> If you insist on taking the result as {a1,a2,a3} (bad for you...) type
>
> % /. {a[1] -> a1, a[2] -> a2, a[3] -> a3}
> {a1, a2, a3}
>
> Regards
> Dimitris
Prev by Date:
**Re: Need algorithm to convert general continued fraction to simple continued fraction**
Next by Date:
**Re: FoourierTransform of a function defined in sections**
Previous by thread:
**Re: Beginner--[Please Help]How to get coefficient list issued from a Series Command**
Next by thread:
**Re: Beginner--[Please Help]How to get coefficient list issued from a Series Command**
| |