Sunday, March 28, 2010

Fourier with Maple

The inspiration for this came from someone who used Maxima to illustrate the concept of Fourier transform. I have ported that idea on maple and also cleaned up the code to make it more flexible. Here one can choose any function f(x) at the top and then executing the interpreted commands one can see the corresponding fourier transform. Also one can control the number of terms. At present it estimates between a period of -Pi to Pi

> f := proc (x)
> x^3-3*x^2+4; This is the function we are estimating
> end proc;

f := proc(x) x^3 - 3*x^2 + 4 end proc

> f(2)
> ;

0

> g := proc (x)
> f(x) * cos(k*x):
> end proc;

g := proc(x) f(x)*cos(k*x) end proc

> h := proc (x)
> f(x) * sin(k*x)
> end proc;

h := proc(x) f(x)*sin(k*x) end proc

> a := proc(k)
> 1/Pi*int(f(x) * cos(k*x),x=-Pi..Pi);
> end proc;

a := proc(k) 1/Pi*int(f(x)*cos(k*x), x = -Pi .. Pi) end proc

> b := proc(k)
> 1/Pi*int(f(x) * sin(k*x),x=-Pi..Pi);
> end proc;

b := proc(k) 1/Pi*int(f(x)*sin(k*x), x = -Pi .. Pi) end proc

> f2 := proc(x)
> a(0)/2+sum(a(k)*cos(k*x)+b(k)*sin(k*x),k=1..20);
> end proc;

f2 := proc(x)
1/2*a(0)
+ sum(a(k)*cos(k*x) + b(k)*sin(k*x), k = 1 .. 20)
end proc

> plot([f2(x),f(x)],x =-10..10, y = -100..100);

>



0 Comments:

Post a Comment

<< Home

Site Meter