1
$\begingroup$

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$?

$\endgroup$

1 Answer 1

1
$\begingroup$

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 *)
$\endgroup$
6
  • $\begingroup$ Here I can realize that if I change the $Nt$ the solution remains the sane $\endgroup$ Mar 31, 2023 at 8:09
  • $\begingroup$ @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: mathematica.stackexchange.com/q/239231/1871 ) $\endgroup$
    – xzczd
    Mar 31, 2023 at 8:52
  • $\begingroup$ This the analytic solution. Could you please show me this comparison with the numerical solution? $\endgroup$ Mar 31, 2023 at 8:57
  • 1
    $\begingroup$ @AthanasiosParaskevopoulos Well, solution comparison is straightforward, and you've already asked such a question: mathematica.stackexchange.com/q/282908/1871 Which part are you still having difficulty? $\endgroup$
    – xzczd
    Mar 31, 2023 at 9:08
  • 1
    $\begingroup$ @AthanasiosParaskevopoulos Yeah, exactly. Solving the equation with NDSolve in Cartesian coordinates should be the easiest. $\endgroup$
    – xzczd
    Mar 31, 2023 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.