MathGroup Archive 2002

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

Search the Archive

Re: fourier transform time

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36439] Re: fourier transform time
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Sat, 7 Sep 2002 02:53:47 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <al9ldd$b2j$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

with your code you compute the expansion coefficents every
time when FS[] is evaluated. Store the values for b[n] with

L = 2;
f[x_] := UnitStep[x - 1];
b[n_] := b[n] = (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}];

FS[N_, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}];

Timing[Plot[FS[30, x], {x, 0, 2}]]

and you need only a 1-3 seconds (depending on your machine)

Regards
  Jens

Steve Story wrote:
> 
> For my PDE class we have been calculating Fourier transforms. The instructor
> arrived today with a printout of two plots of a certain Fourier transform,
> done with a different CAS. The first plot was to 30 terms, the second was to
> 120 terms.
>     Curious, I translated the functions into Mathematica (4.0 on Windows2000
> on a PIII 700) to see how much time this required to process. I was
> Staggered at how much time it took. Here's the code:
> 
> L = 2;
> f[x_] := UnitStep[x - 1];
> b[n_] := (2/L)*Integrate[f[x]*Sin[n*Pi*x/L], {x, 0, L}];
> 
> FS[N_, x_] := Sum[b[n]*Sin[n*Pi*x/L], {n, 1, N}];
> 
> Timing[Plot[FS[30, x], {x, 0, 2}]]
> 
> Out[23]=
> {419.713 Second, \[SkeletonIndicator]Graphics\[SkeletonIndicator]}
> 
> In this case the number of terms is 30.
> 
> The time required per number of terms seems to fit the following polynomial:
> 
> y = 0.3926x^2 + 2.2379x
> 
> This is a large amount of time. I understand that the code is not optimized,
> and was more or less copied from the code in the other CAS, but is this a
> reasonable amount of time, or is something going wrong?  I don't use Mathematica
> because of the speed, but should it be this slow?
> 
> Just curious,
> 
> Steve Story


  • Prev by Date: Re: fourier transform time
  • Next by Date: Solve of inverse quadratic finite element problem - resend
  • Previous by thread: Re: fourier transform time
  • Next by thread: Re: fourier transform time