2
$\begingroup$

I was solving the Helmholtz equation using Mathematica and got as an output an expression which is a summation. I first want to turn this expression into a function of $x$ and $y$. I then want to use Mathematica to plot this function in the domain $D=[-3,3] \times [-3,3]$ but I cannot figure out how to do this. My code to produce the expression is:

eqn = Laplacian[bottom[x, y], {x, y}] + bottom[x, y] == 0;
bc4 = {bottom[-3, y] == 0, bottom[3, y] == 0, 
     bottom[x, -3] == Sin[(\[Pi]x)/6] - Csc[3/Sqrt[2]] Sin[x/Sqrt[2]], 
     bottom[x, 3] == 0};
sol4 = DSolveValue[{eqn, bc4}, bottom[x, y], {x, y}] // FullSimplify  

This outputs:

Inactive[Sum][-((2 Csch[Sqrt[-36 + \[Pi]^2 K[1]^2]] ((-1)^K[1] (1 + 
      (-1)^K[1]) \[Pi]^2 K[1]^2 - (-1 + (-1)^K[1]) (-18 + \[Pi]^2 K[1]^2) 
      Sin[\[Pi]x/6]) Sin[1/6 \[Pi] (3 + x) K[1]] Sinh[1/6 (-3 + y) Sqrt[-36 
      + \[Pi]^2 K[1]^2]])/(\[Pi] K[1] (-18 + \[Pi]^2 K[1]^2))), {K[1], 1, \ 
      [Infinity]}]

Now I tried using:

ans[x_,y_] = Evaluate[sol4]; 
Plot3D[answer, {x, -3, 3}, {y, -3, 3}, ColorFunction -> "TemperatureMap"]

But the plot that's produced just shows nothing. I'm assuming my issue is that the Evaluate function isn't doing what I want it to do but I'm not quite sure what else to use - any thoughts? Do I need to activate the summation?

$\endgroup$
5
  • $\begingroup$ I don't expect that infinite sum to be easily plottable as is. Instead, I would suggest doing something like Plot3D[Evaluate[Activate[sol4 /. Infinity -> 10]], {x, -3, 3}, {y, -3, 3}, ColorFunction -> "TemperatureMap"] instead to see an approximation. $\endgroup$ Commented Dec 12, 2021 at 19:05
  • $\begingroup$ hmm I'm still getting just a blank plot $\endgroup$
    – Mjoseph
    Commented Dec 12, 2021 at 19:12
  • 1
    $\begingroup$ Your bottom[x, -3] condition as currently written is faulty, apparently. Don't forget to separate multiplied variables with a space! bottom[x, -3] == Sin[(π x)/6] - Csc[3/Sqrt[2]] Sin[x/Sqrt[2]] $\endgroup$ Commented Dec 12, 2021 at 19:15
  • $\begingroup$ Oh thanks for pointing that out, I just edited that and still nothing changed though. $\endgroup$
    – Mjoseph
    Commented Dec 12, 2021 at 19:24
  • $\begingroup$ After you correct the Pix to Pi x, the summation includes a $\frac{1}{1-K[1]^2}$ term with K[1] the summation index so it's indeterminate when K[1]=1. Also, the sum is "inactivated" for some reason I don't know. So I first explicitly change K[1]=1 to just k=2 for now (don't know how that would change the solution though), change the upper limit to say 100, and then activate it: mySol = sol4 /. {K[1] -> k, [Infinity] -> 100} mySol[[2]] = {k, 2, 100} myf[x_, y_] = Activate@mySol; Plot3D[myf[x, y], {x, -3, 3}, {y, -3, 3}] And I get a plot which looks reasonable $\endgroup$
    – josh
    Commented Dec 12, 2021 at 20:16

2 Answers 2

5
$\begingroup$

another option instead of skipping the first term is to take its real part. (can easily change this below to takes its absolute value also and compare).

Clear["Global`*"]
eqn = Laplacian[bottom[x, y], {x, y}] + bottom[x, y] == 0;
bc4 = {bottom[-3, y] == 0, bottom[3, y] == 0, 
   bottom[x, -3] == Sin[(Pi*x)/6] - Csc[3/Sqrt[2]] Sin[x/Sqrt[2]], 
   bottom[x, 3] == 0};
sol4 = DSolveValue[{eqn, bc4}, bottom[x, y], {x, y}] // FullSimplify;
sol4 = sol4 /. K[1] -> n;
lim = Limit[sol4[[1]], n -> 1];
sol = Sum[Piecewise[{{Re[lim], n == 1}, {sol4[[1]], n > 1}}], {n, 1,10}];

p1 = Plot3D[sol, {x, -3, 3}, {y, -3, 3}, 
       ColorFunction -> "TemperatureMap", 
       PlotLabel -> "Analytical solution", ImageSize -> 300];

solN = NDSolve[{eqn, bc4}, bottom, {x, -3, 3}, {y, -3, 3}];
p2 = Plot3D[Evaluate[bottom[x, y] /. solN], {x, -3, 3}, {y, -3, 3}, 
      ColorFunction -> "TemperatureMap", 
      PlotLabel -> "numerical solution", ImageSize -> 300];

Grid[{{p1, p2}}]

Mathematica graphics

Increase the summation index to get more accurate analytical solution. Now it uses only 10 terms.

$\endgroup$
2
$\begingroup$

This is what I propose:

The solution is:

$$ \tiny \underset{K[1]=1}{\overset{\infty }{\sum }}-\frac{2 \left((-1)^{K[1]}+1\right) K[1] \left(\frac{\pi ^2 (-1)^{K[1]}}{\pi ^2 K[1]^2-18}+\frac{1}{1-K[1]^2}\right) \text{csch}\left(\sqrt{\pi ^2 K[1]^2-36}\right) \sin \left(\frac{1}{6} \pi (x+3) K[1]\right) \sinh \left(\frac{1}{6} (y-3) \sqrt{\pi ^2 K[1]^2-36}\right)}{\pi } $$

and note there is the term $\frac{1}{1-K[1]^2}$ with $K[1]$ the summation index which is indeterminate at $K[1]=1$. However, the limit at $K[1]=1$ exists:

$$ \lim_{K[1]->1} \text{sol4}=i \csc \left(\sqrt{36-\pi ^2}\right) \cos \left(\frac{\pi x}{6}\right) \sin \left(\frac{1}{6} \sqrt{36-\pi ^2} (y-3)\right) $$

so that we we are left with a complex solution but the PDE is linear so the real and imaginary components of sol4 are solutions. So I propose taking the sum starting with k=2 as one solution (the real component), and the imaginary component of the limit above as a second solution. Note back-substituting the imaginary component of that limit also satisfies the PDE.

Code for real sol:

eqn = Laplacian[bottom[x, y], {x, y}] + bottom[x, y] == 0;
bc4 = {bottom[-3, y] == 0, bottom[3, y] == 0, 
   bottom[x, -3] == Sin[(\[Pi] x)/6] - Csc[3/Sqrt[2]] Sin[x/Sqrt[2]], 
   bottom[x, 3] == 0};
sol4 = DSolveValue[{eqn, bc4}, bottom[x, y], {x, y}] // FullSimplify
mySol = sol4 /. {K[1] -> k, \[Infinity] -> 100}
mySol[[2]] = {k, 2, 100}
myF[x_, y_] = Activate@mySol;
Plot3D[myF[x, y], {x, -3, 3}, {y, -3, 3}]
$\endgroup$

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.