Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#51 2014-02-22 02:34:43

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Fourier series

Yes, that is what happened when I was on M. Why is that happening?


'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'
I'm not crazy, my mother had me tested.

Offline

#52 2014-02-22 02:36:45

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Fourier series

This may be simplistic but you are obviously doing something wrong. Let's concentrate for a minute on my graph. What do you observe and how do you fix it?


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#53 2014-02-22 02:39:00

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Fourier series

I would subtract 0.3 frommy curve

Last edited by Agnishom (2014-02-22 02:40:02)


'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'
I'm not crazy, my mother had me tested.

Offline

#54 2014-02-22 02:40:25

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Fourier series

That suggests that you computed a[0], the constant term wrong.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#55 2014-02-22 02:54:15

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Fourier series

Hmm

(%i10) f(x) := if x>0 then sin(x) else 0$

(%i11) a(n) := (1/%pi)*(integrate(f(x)*cos(n*x),x,-%pi,%pi))$

(%i12) b(n) := (1/%pi)*(integrate(f(x)*sin(n*x),x,-%pi,%pi))$

(%i13) s(x,y) := a(0)/2 + sum((a(n)*cos(n*x)+b(n)*sin(n*x)),n,1,y)$

(%i14) plot2d([f(x),s(x,10)],[x,-%pi,%pi],[box, false]);

Why am I getting so many 'too many context' errors after that? Is it a bug?


'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'
I'm not crazy, my mother had me tested.

Offline

#56 2014-02-22 03:02:00

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Fourier series

I do not know very much about Maxima and its error codes.

I do know that you are not computing a[0] right.

a0 = 1/(2 \[Pi]) Integrate[f[x], {x, -\[Pi], \[Pi]}]

Replace a[0] with a0.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#57 2014-02-22 03:47:25

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Fourier series

Sorry, that is not possible right now.

f[x] is a piecewise function.

f[x_] := If [x>0, Sin[x],0]

How can M know what the following evaluates to without knowing if x is > 0?

a[0] + a[1] Cos[x] + a[2] Cos[2 x] + a[3] Cos[3 x] + 
 a[4] Cos[4 x] + a[5] Cos[5 x] + a[6] Cos[6 x] + a[7] Cos[7 x] + 
 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] + b[6] Sin[6 x] + b[7] Sin[7 x]

'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'
I'm not crazy, my mother had me tested.

Offline

#58 2014-02-22 03:51:35

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Fourier series

Hi;

That is not the correct way to enter the piecewise function.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#59 2014-02-22 03:55:45

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Fourier series

bobbym wrote:

Why didn't you tell me sooner?


'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'
I'm not crazy, my mother had me tested.

Offline

#60 2014-02-22 03:56:53

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Fourier series

About the piecewise function? This was a question to you, not to me.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#61 2014-02-22 03:57:44

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Fourier series

Hm, how does a normal M user enter a piecewise function?


'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'
I'm not crazy, my mother had me tested.

Offline

#62 2014-02-22 03:59:04

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Fourier series

Piecewise[{{0, -\[Pi] <= x <= 0}, {Sin[x], \[Pi] >= x > 0}}]

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#63 2014-02-22 04:00:01

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Fourier series

How is it different from mine?


'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'
I'm not crazy, my mother had me tested.

Offline

#64 2014-02-22 04:12:40

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Fourier series

1) You asked how an M programmer would do it.

2) Yours defines the function passed π, mine does not.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#65 2014-02-22 04:33:37

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Fourier series

Agnishom wrote:

How can M know what the following evaluates to without knowing if x is > 0?

a[0] + a[1] Cos[x] + a[2] Cos[2 x] + a[3] Cos[3 x] + 
 a[4] Cos[4 x] + a[5] Cos[5 x] + a[6] Cos[6 x] + a[7] Cos[7 x] + 
 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] + b[6] Sin[6 x] + b[7] Sin[7 x]

'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'
I'm not crazy, my mother had me tested.

Offline

#66 2014-02-22 04:36:01

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Fourier series

The piecewise function declares that x is sin(x) when x is between 0 and π.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#67 2014-02-22 05:12:04

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Fourier series

Yes, so what?


'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'
I'm not crazy, my mother had me tested.

Offline

#68 2014-02-22 05:19:59

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Fourier series

The formulas produce an expression that will closely approximate the given function between -π and π.

Look at the answer. Notice how closely the blue line ( Fourier series ) covers the red line ( original function ).


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#69 2014-02-22 13:43:31

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Fourier series

That is not my question


'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'
I'm not crazy, my mother had me tested.

Offline

#70 2014-02-22 13:57:25

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Fourier series

I am not following you. Do you mean about the context error?


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#71 2014-02-22 14:57:15

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Fourier series

No, not that. I have now figured out the answer myself.

For now, I am integrating numerically.

(%i1)  f(x) := if x>0 then sin(x) else 0$

(%i2) a(n) := (1/%pi)*(first(quad_qags(f(x)*cos(n*x),x,-%pi,%pi)))$

(%i3) b(n) := (1/%pi)*(first(quad_qags(f(x)*sin(n*x),x,-%pi,%pi)))$

(%i4) s(x,y) := a(0)/2 + sum((a(n)*cos(n*x)+b(n)*sin(n*x)),n,1,y)$

(%i5) plot2d([f(x),s(x,10)],[x,-%pi,%pi],[box, false]);
 ***MESSAGE FROM ROUTINE DQAGS IN LIBRARY SLATEC.
 ***INFORMATIVE MESSAGE, PROG CONTINUES, TRACEBACK REQUESTED
 *  ABNORMAL RETURN
 *  ERROR NUMBER = 2
 *   
 ***END OF MESSAGE
 
 ***MESSAGE FROM ROUTINE DQAGS IN LIBRARY SLATEC.
 ***INFORMATIVE MESSAGE, PROG CONTINUES, TRACEBACK REQUESTED
 *  ABNORMAL RETURN
 *  ERROR NUMBER = 2
 *   
 ***END OF MESSAGE
 
 ***MESSAGE FROM ROUTINE DQAGS IN LIBRARY SLATEC.
 ***INFORMATIVE MESSAGE, PROG CONTINUES, TRACEBACK REQUESTED
 *  ABNORMAL RETURN
 *  ERROR NUMBER = 2
 *   
 ***END OF MESSAGE
 
 ***MESSAGE FROM ROUTINE DQAGS IN LIBRARY SLATEC.
 ***INFORMATIVE MESSAGE, PROG CONTINUES, TRACEBACK REQUESTED
 *  ABNORMAL RETURN
 *  ERROR NUMBER = 2
 *   
 ***END OF MESSAGE
 
 ***MESSAGE FROM ROUTINE DQAGS IN LIBRARY SLATEC.
 ***INFORMATIVE MESSAGE, PROG CONTINUES, TRACEBACK REQUESTED
 *  ABNORMAL RETURN
 *  ERROR NUMBER = 2
 *   
 ***END OF MESSAGE
 
 ***MESSAGE FROM ROUTINE DQAGS IN LIBRARY SLATEC.
 ***INFORMATIVE MESSAGE, PROG CONTINUES, TRACEBACK REQUESTED
 *  ABNORMAL RETURN
 *  ERROR NUMBER = 2
 *   
 ***END OF MESSAGE
 
 ***MESSAGE FROM ROUTINE DQAGS IN LIBRARY SLATEC.
 ***INFORMATIVE MESSAGE, PROG CONTINUES, TRACEBACK REQUESTED
 *  ABNORMAL RETURN
 *  ERROR NUMBER = 2
 *   
 ***END OF MESSAGE
 
 ***MESSAGE FROM ROUTINE DQAGS IN LIBRARY SLATEC.
 ***INFORMATIVE MESSAGE, PROG CONTINUES, TRACEBACK REQUESTED
 *  ABNORMAL RETURN
 *  ERROR NUMBER = 2
 *   
 ***END OF MESSAGE
 
 ***MESSAGE FROM ROUTINE DQAGS IN LIBRARY SLATEC.
 ***INFORMATIVE MESSAGE, PROG CONTINUES, TRACEBACK REQUESTED
 *  ABNORMAL RETURN
 *  ERROR NUMBER = 2
 *   
 ***END OF MESSAGE
 
 ***MESSAGE FROM ROUTINE DQAGS IN LIBRARY SLATEC.
 ***INFORMATIVE MESSAGE, PROG CONTINUES, TRACEBACK REQUESTED
 *  ABNORMAL RETURN
 *  ERROR NUMBER = 2
 *   
 ***END OF MESSAGE
 
(%o5)

Yields the attached image

The polynomial is the following

(%i6) s(x,10);
      1.3877787807814457E-16 sin(10 x)   0.02020202020202 cos(10 x)
(%o6) -------------------------------- - --------------------------
                    %pi                             %pi
   3.3219954564955856E-16 sin(9 x)   1.3877787807814457E-17 cos(9 x)
 + ------------------------------- - -------------------------------
                 %pi                               %pi
   4.163336342344337E-17 sin(8 x)   0.031746031746032 cos(8 x)
 + ------------------------------ - --------------------------
                %pi                            %pi
   3.2265856653168612E-16 sin(7 x)   5.7245874707234634E-17 cos(7 x)
 - ------------------------------- - -------------------------------
                 %pi                               %pi
   3.9091435841719085E-16 sin(6 x)   0.057142857142857 cos(6 x)
 - ------------------------------- - --------------------------
                 %pi                            %pi
   4.8572257327350599E-17 sin(5 x)   1.6653345369377348E-16 cos(5 x)
 - ------------------------------- + -------------------------------
                 %pi                               %pi
   2.0816681711721685E-16 sin(4 x)   0.13333333333333 cos(4 x)
 - ------------------------------- - -------------------------
                 %pi                            %pi
   3.2612801348363973E-16 sin(3 x)   1.9081958235744878E-17 cos(3 x)
 + ------------------------------- + -------------------------------
                 %pi                               %pi
   1.6653345369377348E-16 sin(2 x)   0.66666666666667 cos(2 x)
 - ------------------------------- - -------------------------
                 %pi                            %pi
   1.570796326794897 sin(x)   1.1102230246251565E-16 cos(x)   1.0
 + ------------------------ - ----------------------------- + ---
             %pi                           %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'
I'm not crazy, my mother had me tested.

Offline

#72 2014-02-22 15:04:34

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Fourier series

There are a lot of error messages in that calculation. Also, many of those coefficients are just fungi.

But that is the correct answer. Very good.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#73 2014-02-22 15:06:08

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Fourier series

fungi?


'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'
I'm not crazy, my mother had me tested.

Offline

#74 2014-02-22 15:20:32

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

Re: Fourier series

A number that is very, very tiny so it is obviously 0.


In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

#75 2014-02-22 15:43:36

Agnishom
Real Member
From: Riemann Sphere
Registered: 2011-01-29
Posts: 24,974
Website

Re: Fourier series

All tiny numbers are essentially zero? Why?

There are a lot of error messages in that calculation.

Not the calculation, its just the plotting part.

Last edited by Agnishom (2014-02-22 15:50:39)


'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'
I'm not crazy, my mother had me tested.

Offline

Board footer

Powered by FluxBB