You are not logged in.

- Topics: Active | Unanswered

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 91,686

Hi;

At the request of Agnishom, this thread will now deal with Fourier series and how to do them using your package.

We will start with the simple y = x between -π and π.

We have the equations:

```
f[x_] := x;
a[n_] := 1/\[Pi] Integrate[f[x] Cos[n*x], {x, -\[Pi], \[Pi]}]
b[n_] := 1/\[Pi] Integrate[f[x] Sin[n*x], {x, -\[Pi], \[Pi]}]
```

a[0],a[1],...a[4] will all be 0

b[0] = 0

b[1] = 2

b[2] = -1

b[3] = 2 / 3

b[4] = - 1 / 2

So the Fourier series is

`b[0] + b[1] Sin[x] + b[2] Sin[2 x] + b[3] Sin[3 x]+b[4] Sin[4x]`

```
Plot[{2 Sin[x] - Sin[2 x] + 2/3 Sin[3 x] - 1/2 Sin[4 x],
x}, {x, -\[Pi], \[Pi]}]
```

**In mathematics, you don't understand things. You just get used to them.**

**Online**

Hmm

```
(%i1) load(fourie)$
(%i2) f(x) = y$
(%i3) fourier(f,x,1);
(%t3) a = f
0
2 f sin(%pi n)
(%t4) a = --------------
n %pi n
(%t5) b = 0
n
(%o5) [%t3, %t4, %t5]
```

EDIT: Sorry, I did not see the edited portion of your last post, the last time

*Last edited by Agnishom (2014-02-20 02:55:48)*

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 91,686

Please use Mathematica else we will get confused over differences in packages. Also follow what I did in post 1 so that you can see the workings.

**In mathematics, you don't understand things. You just get used to them.**

**Online**

bobbym wrote:

We have the equations:

`f[x_] := x; a[n_] := 1/\[Pi] Integrate[f[x] Cos[n*x], {x, -\[Pi], \[Pi]}] b[n_] := 1/\[Pi] Integrate[f[x] Sin[n*x], {x, -\[Pi], \[Pi]}]`

```
(%i1) f(x) := x$
(%i2) a(n) := (1/%pi)*(integrate(f(x)*cos(n*x),x,-%pi,%pi))$
(%i3) b(n) := (1/%pi)*(integrate(f(x)*sin(n*x),x,-%pi,%pi))$
```

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

bobbym wrote:

Please use Mathematica else we will get confused over differences in packages. Also follow what I did in post 1 so that you can see the workings.

OK, sorry for the confusion. I will do that when I get a chance to reboot.

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 91,686

Hi;

This is what it looks like.

**In mathematics, you don't understand things. You just get used to them.**

**Online**

I will do the Mathematica part once I reboot. For now, Is this ok?

```
(%i1) f(x) := x$
(%i2) a(n) := (1/%pi)*(integrate(f(x)*cos(n*x),x,-%pi,%pi))$
(%i3) b(n) := (1/%pi)*(integrate(f(x)*sin(n*x),x,-%pi,%pi))$
(%i4) b(0) + b(1)*sin(x) + b(2)*sin(2*x) + b(3)*sin(3*x)+b(4)*sin(4*x);
sin(4 x) 2 sin(3 x)
(%o4) - -------- + ---------- - sin(2 x) + 2 sin(x)
2 3
(%i5) print("Hmmm");
Hmmm
(%o5) Hmmm
(%i6) plot2d (%o4, [x, -%pi, %pi])$
```

The image is attached

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 91,686

That looks okay, very good.

**In mathematics, you don't understand things. You just get used to them.**

**Online**

a[0],a[1],...a[4] will all be 0

So, why calculate any of them? Why declare the a[n_] function at all?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 91,686

Because most of the time they will not be 0. Usually there are cos and sin terms.

**In mathematics, you don't understand things. You just get used to them.**

**Online**

What does a fourier series look like without the sigma notaiton

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 91,686

Sigma notation was not used. That is a fine point. It looks like a big polynomial except powers of x are replaced with trig functions.

**In mathematics, you don't understand things. You just get used to them.**

**Online**

Show me one such poly please.

By the way, the attached image looks interesting.

```
(%i12) b(0);(%o12) 0
(%i13) b(0) + b(1)*sin(x)
;
(%o13) 2 sin(x)
(%i14) b(0) + b(1)*sin(x) + b(2)*sin(2*x);
(%o14) 2 sin(x) - sin(2 x)
(%i15) b(0) + b(1)*sin(x) + b(2)*sin(2*x) + b(3)*sin(3*x);
2 sin(3 x)
(%o15) ---------- - sin(2 x) + 2 sin(x)
3
(%i16) b(0) + b(1)*sin(x) + b(2)*sin(2*x) + b(3)*sin(3*x)+b(4)*sin(4*x); sin(4 x) 2 sin(3 x)
(%o16) - -------- + ---------- - sin(2 x) + 2 sin(x)
2 3
(%i17) b(0) + b(1)*sin(x) + b(2)*sin(2*x) + b(3)*sin(3*x)+b(4)*sin(4*x)+b(5)*sin(5*x);
2 sin(5 x) sin(4 x) 2 sin(3 x)
(%o17) ---------- - -------- + ---------- - sin(2 x) + 2 sin(x)
```

`(%i22) plot2d ([%o12,%o13,%o14,%o15,%o16,%o17,f], [x, -%pi, %pi],[box, false])$`

I remember that M has an Animate command that could produce a cooler animation

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 91,686

Hi;

I did not say that they were polynomials, they just look like them.

**In mathematics, you don't understand things. You just get used to them.**

**Online**

Why is this not a polynomial?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 91,686

A polynomial is an expression made up of integer powers of x.

**In mathematics, you don't understand things. You just get used to them.**

**Online**

Non-negative inteher

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 91,686

Yes, that is correct.

Tomorrow we will try another.

**In mathematics, you don't understand things. You just get used to them.**

**Online**

It should have been integer rather than inteher.

Tomorrow with respect to whom?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 91,686

For you of course.

**In mathematics, you don't understand things. You just get used to them.**

**Online**

OK, it is now tomorrow with respect to me

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 91,686

Yes, I need some time to prepare another example. Also, I am making dinner.

**In mathematics, you don't understand things. You just get used to them.**

**Online**

Will you feed me tonight?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 91,686

Of course, ever had pizza?

**In mathematics, you don't understand things. You just get used to them.**

**Online**

Of course, do you know what a gel candle is?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'You have made another human being happy. There is no greater accomplishment.' -bobbym

Offline