1

enter image description here

Definition of function f

f[θ_] = 1 + Cos[2 θ] + Sin[3 θ]
Plot[f[θ], {θ, 0, 2 π}]

Computation of the Fourier coefficients

a[0] = 1/(2 π)*Integrate[f[θ], {θ, 0, 2 π}]
a[n_] = 1/(π a^n)*Integrate[f[θ]*Cos[n*θ], {θ, 0, 2 π}]
 Simplify[a[n], Element[n, Integers]]
 b[n_] = 1/(π a^n)*Integrate[f[θ]*Sin[n*θ], {θ, 0, 2 π}]
 Simplify[b[n], Element[n, Integers]]

Construction of the exact solution resulting in the following warning:

  Nt = 10
  u[ρ_, θ_] = Sum[ρ^k*b[k]*Sin[(k)*θ], {k, 0, Nt}]

Power::infy: Infinite expression 1/0 encountered.

Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered.

What must I change to my code to receive the first ten coefficients of $a_n$ and $b_n$?

user64494
  • 26,149
  • 4
  • 27
  • 56

1 Answers1

1

You've encountered a known issue of Integrate elaborated in the following post:

Usage of Assuming for Integration

For your specific problem one possible work-around is to avoid symbolic integration for general n by changing = to :=:

f[θ_] = 1 + Cos[2 θ] + Sin[3 θ];
a[0] = 1/(2 π) Integrate[f[θ], {θ, 0, 2 π}];

a[n_] := 1/(π a^n) Integrate[f[θ] Cos[n θ], {θ, 0, 2 π}] b[n_] := 1/(π a^n) Integrate[f[θ] Sin[n θ], {θ, 0, 2 π}]

Nt = 10; u[ρ, θ] = Sum[ρ^k (b[k] Sin[k θ] + a[k] Cos[k θ]), {k, 0, Nt}]

(* 1 + (ρ^2 Cos[2 θ])/a^2 + (ρ^3 Sin[3 θ])/a^3 *)

Another work-around is to use Limit to keep away from the removable singularity:

f[θ_] = 1 + Cos[2 θ] + Sin[3 θ];
a[0] = Integrate[f[θ], {θ, 0, 2 Pi}]/(2 π);
a[n_] = Integrate[f[θ] Cos[n θ], {θ, 0, 2 Pi}]/(π a^n);
b[n_] = Integrate[f[θ] Sin[n θ], {θ, 0, 2 Pi}]/(π a^n);

Nt = 10; u[ρ, θ] = a[0] + Sum[Limit[ρ^k (b[k] Sin[k θ] + a[k] Cos[k θ]), k -> i], {i, Nt}]

(* 1 + (ρ^2 Cos[2 θ])/a^2 + (ρ^3 Sin[3 θ])/a^3 *)

xzczd
  • 65,995
  • 9
  • 163
  • 468
  • Here I can realize that if I change the $Nt$ the solution remains the sane – Athanasios Paraskevopoulos Mar 31 '23 at 08:09
  • @AthanasiosParaskevopoulos Yes, because of the special b.c. f[θ_] = 1 + Cos[2 θ] + Sin[3 θ]. This b.c. leads to a series solution that only has finite number of term. One can further verify this by comparing the analytic solution with the numerical solution. (BTW, similar problems seem to be frequently used for pedagogical purposes, another related post I can remember: https://mathematica.stackexchange.com/q/239231/1871 ) – xzczd Mar 31 '23 at 08:52
  • This the analytic solution. Could you please show me this comparison with the numerical solution? – Athanasios Paraskevopoulos Mar 31 '23 at 08:57
  • 1
    @AthanasiosParaskevopoulos Well, solution comparison is straightforward, and you've already asked such a question: https://mathematica.stackexchange.com/q/282908/1871 Which part are you still having difficulty? – xzczd Mar 31 '23 at 09:08
  • So I have to find the numerical solution and the to plot the difference! Right? – Athanasios Paraskevopoulos Mar 31 '23 at 09:21
  • 1
    @AthanasiosParaskevopoulos Yeah, exactly. Solving the equation with NDSolve in Cartesian coordinates should be the easiest. – xzczd Mar 31 '23 at 09:32