Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Multiline functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112784] Re: Multiline functions
  • From: dr DanW <dmaxwarren at gmail.com>
  • Date: Thu, 30 Sep 2010 04:52:26 -0400 (EDT)
  • References: <i7uses$ram$1@smc.vnet.net>

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
used.

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,
Pi}]

SinCoefficient[f_, 0] := 0

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

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

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

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.

Daniel


  • 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