Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have used the following code to generate eigenfunctions of a PDE:

{vals, funs} = 
  NDEigensystem[{-Laplacian[u[x, y], {x, y}], 
    DirichletCondition[u[x, y] == 0, True]}, 
   u[x, y], {x, y} \[Element] 
    Polygon[{{-1/2, -1/2}, {1/2, -1/2}, {1/2, 1/2}, {-1/2, 1/2}}], 4];

By applying funs[[3]]you can see that the third eigenfunction is an interpolating function:

Interpolating Function

With contour plot:

Plot of third eigenfunction

What I now wish to do is to transform this function by rotating it anticlockwise by $\frac{\pi}{2}$ about the origin.

Let's say that the points lying on our eigenfunction are $(x,y,f(x,y))$.

I now wish to effectively move these points by perhaps taking $(x,y) \mapsto (y,-x)$

I cannot seem to find anything online to describe how to do this for these interpolating functions.

I tried defining a function R and applying it to funs[[3]] with no success.

R := Function[g, g /. Thread[{x, y} -> ({y,-x})]]

I thought that this may work as it would replace the coordinates for me, but I now know that my logic is flawed.

Please note: I am not asking how to rotate the contourplot (even though a contour plot of the transformed eigenfunction should look identical to it) I would like a transformation to be applied to the function because I intend to use it later on.

I would be really grateful if somebody could help me on this - I've been playing around with code for the past three hours.

share|improve this question
    
Can't test on mobile, but what about simply f[y, - x]? Where f is the initial interpolating function. – LLlAMnYP Feb 3 at 23:42
    
Doing so doesn't give off an error but the contour plot is blank. This might be my fault though - I'm very new to mathematica. – Mr S 100 Feb 3 at 23:54
    
There's nothing wrong with your approach (with is essentially from my answer here), as you can see by calling R[funs[[1]]]. You just have to watch out whether you have an object with Head of InterpolationFunction or not. What your solver returns is an interpolating function, evaluated at a symbolic argument (not the actual function!). In rotating it, you have to replace the symbolic arguments by rotated versions. For what you're after, it may be better to change NDEigensystem by replacing u[x,y] with u in argument 2. – Jens Feb 4 at 0:30
up vote 6 down vote accepted
rotation = {x, y}.{{Cos[t], Sin[t]}, {-Sin[t], Cos[t]}};
f[t_] = funs[[3]] /. {x -> rotation[[1]], y -> rotation[[2]]};
Manipulate[
 ContourPlot[f[t], {x, -.3, .3}, {y, -.3, .3}], {t, -\[Pi], \[Pi]}]

enter image description here

share|improve this answer
    
This looks really good but unfortunately I keep getting the error 'Tag Plus in (Sin[x]+Sin[y])[t_] is Protected'. What am I doing wrong? – Mr S 100 Feb 3 at 23:55
    
You have a definition of f before. Clear[f] or used different symbol. – Algohi Feb 3 at 23:57
    
Silly me - you were right! It's all working now. Could I ask why you've indexed as rotation[[1]] and rotation[[2]]? Thanks – Mr S 100 Feb 4 at 0:05
    
rotation is a vector and the first component has to be in position of x and the second component has to be in position of y (look at the [x,y] at the end of your function). – Algohi Feb 4 at 0:10

You can use RotationTransform.

With[{rot = funs[[3]] /. Inner[Rule, {x, y}, RotationTransform[π/2][{x, y}], List]},
 ContourPlot[rot, {x, -.5, .5}, {y, -.5, .5}]
]

enter image description here

Hope this helps.


Also with Manipulate

Manipulate[
 With[{rot = funs[[3]] /. Inner[Rule, {x, y}, RotationTransform[θ][{x, y}], List]},
  Quiet@ContourPlot[rot, {x, -.5, .5}, {y, -.5, .5}]],
 Column[{
   AngularGauge[Dynamic@θ, {0, 2 π}, 
    ScaleOrigin -> {0, 2 π}, ScaleDivisions -> {8, 2}, 
    TargetUnits -> "Radians", GaugeLabels -> "Radians"]}],
 ControlPlacement -> Left
 ]

enter image description here

share|improve this answer
    
This also works perfectly! Thank you so much – Mr S 100 Feb 4 at 0:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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