MathGroup Archive 2010

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

Search the Archive

Re: Multiline functions

Dude, where to even start. Perhaps it looks awkward because you typed
in code intended for a another language.  Oddly, it will only work for
your test case; in LaplaceOnUnitCircle, sum is accumulated but never

Neglecting the fact that Mathematica has built in capability for this
problem, here is how to code your solution in real Mathematica:

CosCoefficient[f_, n_] := (1/Pi)*Integrate[f[x]*Cos[n*x], {x, -Pi,

SinCoefficient[f_, 0] := 0

SinCoefficient[f_, n_] := (1/Pi)*Integrate[f[x]*Sin[n*x], {x, -Pi,

LaplaceOnUnitCircle2[phi_, order_] := CosCoefficient[phi, 0]/2 +
   Sum[r^n*(CosCoefficient[phi, n]*Cos[n*x] + SinCoefficient[phi,
    {n, 1, order}]

Notice that I only have to use Sum[], none of that Fortrany "for" loop

The (or at least, one) way to do this using the full capabilities of
Mathematica is:

LaplaceOnUnitCircle3[phi_, order_] := FourierTrigSeries[phi[x], x,
order] /.
   {Cos[(n_Integer)*x] :> r^n*Cos[n*x], Cos[x] -> r*Cos[x],
    Sin[(n_Integer)*x] :> r^n*Sin[n*x], Sin[x] -> r*Sin[x]}

I'm helping because I'm like that.  However, in the future, if you do
not wish to become a flame target, I would strongly suggest that you
make an effort to learn some aspect of a language on your own before
running to the users group for help.  It may already be too late.


  • Prev by Date: Re: calculate vertex of a parabola
  • Next by Date: Re: Root Finding Methods Gaurenteed to Find All Root Between (xmin, xmax)
  • Previous by thread: Multiline functions
  • Next by thread: Re: Multiline functions