2
$\begingroup$

I am trying to plot the first eigenvalue of the Laplacian operator with zero Dirichlet condition on following figure against decreasing values of $\varepsilon$.

my region

I used Polygon to create the first figure with $\varepsilon=0.9$:

r = Graphics[Polygon[{{0, 0}, {0, 1}, {1, 1}, {1, 0.9}, {2, 0.9}, {2, 1}, {3, 1}, {3, 0}, 
      {2, 0}, {2, 0.1}, {1, 0.1}, {1, 0}}]];

Then used DiscretizeGraphics to form the region:

dr = DiscretizeGraphics[r]

Using NDEigenSystem the Eigenvalue was obatined.

{vals, funs} = NDEigensystem[
   {-Laplacian[u[x, y], {x, y}], DirichletCondition[u[x, y] == 0, True]}, 
   u[x, y], {x, y} ∈ dr, 1, 
   Method -> 
     {"SpatialDiscretization" -> {"FiniteElement", 
         {"MeshOptions" -> {"MaxCellMeasure" -> 0.01}}}}
 ];

For few epsilons I can use the process described above by changing the polygon, and drawing a new region. Like:

Clear[r, dr, vals, funs];

r = Graphics[Polygon[{{0, 0}, {0, 1}, {1, 1}, {1, 0.8}, {2, 0.8}, {2, 1}, {3, 1}, {3, 0}, 
      {2, 0}, {2, 0.2}, {1, 0.2}, {1, 0}}]];
dr = DiscretizeGraphics[r]

{vals, funs} = NDEigensystem[
   {-Laplacian[u[x, y], {x, y}], DirichletCondition[u[x, y] == 0, True]},
   u[x, y], {x, y} ∈ dr, 1, 
   Method -> 
     {"SpatialDiscretization" -> {"FiniteElement", 
         {"MeshOptions" -> {"MaxCellMeasure" -> 0.01}}}}
  ];

list = Append[list, vals]
Flatten[%]

My question is, can this process by done within a loop?

Or is there in way to vary $\varepsilon$ without typing the above code block manually for different values of $\varepsilon$?

$\endgroup$
5
  • $\begingroup$ Your drawing and code do not agree on what $\varepsilon$ is supposed to be. In any event: With[{ε = 0.2}, DiscretizeGraphics[Graphics[Polygon[{{0, 0}, {0, 1}, {1, 1}, {1, (1 + ε)/2}, {2, (1 + ε)/2}, {2, 1}, {3, 1}, {3, 0}, {2, 0}, {2, (1 - ε)/2}, {1, (1 - ε)/2}, {1, 0}}]]]]. You can make a Manipulate[] out of this if you are so inclined. $\endgroup$ Commented Jun 8, 2016 at 17:08
  • $\begingroup$ I did what you suggested using Manipulate[]. But that is not what I need. I need the whole process in a loop in the following logic order: (1) Draw and store the polygon (2) Discretize and store the polygon (3) Solve the eigensystem, append the required value in a list (4) Repeat steps 1 to 3 (5) Plot the list versus ε @J.M. $\endgroup$ Commented Jun 8, 2016 at 17:34
  • $\begingroup$ Then use Table[]. I've given you something to start with; you can embed the contents of the With[] in there along with the needed call to NDSolve[]. $\endgroup$ Commented Jun 8, 2016 at 17:36
  • $\begingroup$ Can you give me a small example to clarify your point? @J.M. $\endgroup$ Commented Jun 8, 2016 at 17:43
  • $\begingroup$ guy141 I have given you an example that is more "Mathematica-like" and avoids the use of loops. This is probably what @J.M. was hinting at. I would urge you to spend some time adapting those result to achieve your final goal, rather than trying to follow the procedural approach you pointed out in your comment above. Mathematica constructs that avoid loops tend to be cleaner, and sometimes faster as well. $\endgroup$
    – MarcoB
    Commented Jun 8, 2016 at 18:06

1 Answer 1

3
$\begingroup$

Once you have the NDEigensystems code in place, it is not difficult to extend it to work on multiple regions (this is, I believe, what @JM was nudging you towards).

For instance, generate a list of such polygons using Table:

r = Table[
  Graphics[
   Polygon[{
     {0, 0}, {0, 1}, {1, 1},
     {1, (1 + epsilon)/2}, {2, (1 + epsilon)/2}, {2, 1},
     {3, 1}, {3, 0}, {2, 0},
     {2, (1 - epsilon)/2}, {1, (1 - epsilon)/2}, {1, 0}}]
   ],
  {epsilon, 0.1, 0.9, 0.1}
 ]

polygons

Generate discretized regions them by mapping DiscretizeGraphics over the list:

dr = DiscretizeGraphics /@ r

regions

Turn the call to NDEigensystem into a function that takes an integration region as a variable using pure functions (look up # and &), then collect your results in appropriately shaped lists vals and funs:

NDEigensystem[
    {-Laplacian[u[x, y], {x, y}], DirichletCondition[u[x, y] == 0, True]},
    u[x, y], {x, y} \[Element] #, 1,
    Method ->
     {"SpatialDiscretization" ->
       {"FiniteElement", {"MeshOptions" -> {"MaxCellMeasure" -> 0.01}}}
     }
   ] & /@ dr;

{vals, funs} = Transpose@%

results

$\endgroup$
6
  • $\begingroup$ Excellent. This is what I was looking for. Thanks a lot. @MarcoB $\endgroup$ Commented Jun 8, 2016 at 18:11
  • $\begingroup$ Can this code be modified to store more than one eigenvalue for each figure ( like set 'a' storing 20 eigenvalues of the first figure, set 'b' 20 eigenvalues of the second figure, and so on ) ? I am trying to see how the eigenvalues change with shape. @MarcoB $\endgroup$ Commented Jul 1, 2016 at 16:04
  • $\begingroup$ @guy141 I would think it should just be a matter of changing the 1 in NDEigensystem to the number of eigenvalues/eigenfunctions you want to calculate out for each shape. You may also have to adjust the Transpose expression to better suit your needs in that case, since each output will be a more complex list. $\endgroup$
    – MarcoB
    Commented Jul 1, 2016 at 16:09
  • $\begingroup$ By changing the 1 in NDEigensystem command I got more than one value. But I couldn't extract it out later figure-wise. What kind of change in Transpose are you talking about? @MarcoB $\endgroup$ Commented Jul 1, 2016 at 16:16
  • $\begingroup$ @guy141 Well I don't really know what you want to do with them, but if you request e.g. two eigenstates, then Transpose@% will give you a list of lists, the first being a list of pairs of eigenvalues, and the second being a list of the corresponding pairs of eigenfunctions. I am not sure how you want to visualize them, so you will have to provide more details or, perhaps better, start another question about it, since the issue is not really linked to this one anymore. $\endgroup$
    – MarcoB
    Commented Jul 1, 2016 at 17:15

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.