MathGroup Archive 2005

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

Search the Archive

Re: Preventing LegendreP from self-extracting in manipulations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57865] Re: Preventing LegendreP from self-extracting in manipulations
  • From: "Carl K. Woll" <carlw at u.washington.edu>
  • Date: Fri, 10 Jun 2005 02:29:40 -0400 (EDT)
  • Organization: University of Washington
  • References: <d893ok$svp$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"Vladislav" <kazimir04 at yahoo.co.uk> wrote in message 
news:d893ok$svp$1 at smc.vnet.net...
> Hi, all,
>
> I have already tried to post the message, but it went lost. I repeat it
> as a new therad.
>
> Can somebody help me with the following. I need present some functions
> (prolate spheroidal functions) in the basis of the Legendre
> polynomials. I.e.
> I have functions like
>
> FF1 = 0.6 LegendreP[5, #1] + 0.7 LegendreP[6, #1] &
> FF2 = 0.3 LegendreP[5, #1] + 0.2 LegendreP[6, #1] &
>
> I want to manipulate these functions and remain in the basis of prolate
> functions.
> For example I want to create a linear combination of functions, or
> something like this.
>
> FF = .2FF1[#1] + .3FF2[#1] &
>
> It works well from the point of view of finding the numerical result,
> but it do not give
> the presentaion of the function in the basis of the Legendre
> polynomials
>
> I would like to have create a function which would give the result like
>
> FFX = 0.9 LegendreP[5, #1] + 0.9 LegendreP[6, #1] &, so that I could
> see the presentaion
> of the function by typing FFX and obtaining  0.9 LegendreP[5, #1] + 0.9
> LegendreP[6, #1] &.
> In practice these functions contain much more terms and having the form
> like
> 0.9 LegendreP[5, #1] + 0.9 LegendreP[6, #1] & is very important. In
> the same way
> I would not like to have the explicit presentation as plolinomials,
> like -0.28125+
> 1.6875  w + 5.90625 w^2 + .. because of loss of accuracy for future
> results.
>
> Sincerely,
>
> Vladislav
>

Vladislav,

How about introducing a framework, a la InterpolatingFunction. For example, 
let's call the framework lsFunction, where ls is shorthand for Legendre 
Series. lsFunction takes a single argument, the list for the coefficients of 
the LegendreP polynomials, and returns a function. I used a regular function 
instead of a pure function so that I can make sure the explicit LegendreP 
polynomials are never expanded out.

Define rule for numeric input:

lsFunction[c_][x_?NumericQ] := c . LegendreP[Range[0, Length[c] - 1], x]

Define rules for adding lsFunctions:

lsFunction /: lsFunction[c1_] + lsFunction[c2_] :=
  lsFunction[Total[PadRight[{c1, c2}, {2, Max[Length[c1], Length[c2]]}]]]
lsFunction /: lsFunction[c1_][x_] + lsFunction[c2_][x_] :=
  lsFunction[Total[PadRight[{c1, c2}, {2, Max[Length[c1], Length[c2]]}]]][x]

Define rules for multiplying by a scalar:

lsFunction /: a_?NumericQ lsFunction[c_] := lsFunction[a c]
lsFunction /: a_?NumericQ lsFunction[c_][x_] := lsFunction[a c][x]

Define rules for formatting:

Format[lsFunction[c_List]] := lsFunction["<>"]
Format[lsFunction[c_][x_]] :=
 c . Table[Subscript[P, n][x], {n, 0, Length[c] - 1}]

For your examples, we would have:

In[40]:=
FF1 = lsFunction[{0, 0, 0, 0, 0, .6, .7}]
FF2 = lsFunction[{0, 0, 0, 0, 0, .3, .2}]
Out[40]=
lsFunction["<>"]
Out[41]=
lsFunction["<>"]

Now, we can do things like taking linear combinations of lsFunctions:

In[42]:=
FF=.2FF1+.3FF2

Out[42]=
lsFunction["<>"]

Let's apply FF to a variable

In[43]:=
FF[x]

Out[43]=
0.21 Subscript[P, 5][x] + 0.2 Subscript[P, 6][x]

We see that the LegendreP polynomials (the Subscript[P,_] will look better 
in the Front End) haven't been expanded out. If instead we apply FF to a 
number, we get:

In[44]:=
FF[.1]

Out[44]=
-0.0122118

You can also do other things like define rules for multiplying two 
lsFunctions, or integration and differentiation.

Carl Woll
Wolfram Research 



  • Prev by Date: Re: Preventing LegendreP from self-extracting in manipulations
  • Next by Date: saving the kernel
  • Previous by thread: Re: Preventing LegendreP from self-extracting in manipulations
  • Next by thread: Re: Preventing LegendreP from self-extracting in manipulations