Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2010

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

Search the Archive

Multiline functions

  • To: mathgroup at
  • Subject: [mg112748] Multiline functions
  • From: Sam Takoy <sam.takoy at>
  • Date: Wed, 29 Sep 2010 04:13:43 -0400 (EDT)


I'm not sure if I'm approaching functions that require several lines 
properly. Here's my approach to solving Laplace's equation on the unit 
circle with Dirichlet boundary conditions. (Construct partial Fourier 
series, multiply each term by r^n and sum.) Something about my code 
seems terribly awkward. I'm looking for comments on how to improve it.
(Just the code. I know that mathematically there may be better ways.)

Thanks in advance,


FourierCoefficients[f_, order_] := (
   out = {1/(2 Pi) Integrate[f[a], {a, -Pi, Pi}]};
   For[n = 1, n < order, n = n + 1,
    out = Append[
      out, {1/Pi Integrate[f[a] Cos[n a], {a, -Pi, Pi}],
       1/Pi Integrate[f[a] Sin[n a], {a, -Pi, Pi}]}]];

LaplaceOnUnitCircle[phi_, order_] := (
    f[r_, alpha_] = (
      fc = FourierCoefficients[phi, order];
      sum = fc[[1]];
      For[n = 1, n < order, n = n + 1,
       sum =
         sum + r^n (fc[[n + 1]][[1]] Cos[n alpha] +
             fc[[n + 1]][[2]] Sin[n alpha]);
LaplaceOnUnitCircle[Cos, 5][r, \[Alpha]]

Answer: r Cos[\[Alpha]] - correct.

  • Prev by Date: Re: Determining a valid URL
  • Next by Date: Re: Interpolate in polar coordinates or cartesian
  • Previous by thread: Re: Poisson's integral formula doesn't work
  • Next by thread: Re: Multiline functions