The geometric interpretation of a function of a complex variable with Mathematica? - plot

How can I write the code in mathematica to see the result like this:
As you see we have the complex function w=f(z), where z=x+iy and w=u+iv.
In this example w=sin z, and we see the image of vertical line x=c is hyperbola. (Left)
and the image of horizontal line y=c is an elliptic. (Right)
This picture took from the book "Complex Variables and Applications, by James Ward Brown, Ruel Vance Churchill", 8th edition: pages 331 and 333 or third edition pages 96-97

Something like this?
ClearAll[u, v, f];
f[z_] := Sin[z]
u[x_, y_] := Re#f[x + I*y];
v[x_, y_] := Im#f[x + I*y];
EDIT: This just produces the whole thing. If you want to just see what happens for a single path parallel to the imaginary axis, try
ParametricPlot[{u[5, y], v[5, y]}, {y, -3, 3}]
or for the same parallel to the real axis try
ParametricPlot[{u[x, 1], v[x, 1]}, {x, -3, 3}]
EDIT2: Interactive:
ClearAll[u, v, f];
f[z_] := Sin[z]
u[x_, y_] := Re#f[x + I*y];
v[x_, y_] := Im#f[x + I*y];
Manipulate[
Show[
Graphics[{Line[{p1, p2}]}, PlotRange \[Rule] 3, Axes \[Rule] True],
ParametricPlot[
{u[p1[[1]] + t (p2[[1]] - p1[[1]]),
p1[[2]] + t (p2[[2]] - p1[[2]])],
v[p1[[1]] + t (p2[[1]] - p1[[1]]),
p1[[2]] + t (p2[[2]] - p1[[2]])]},
{t, 0, 1},
PlotRange \[Rule] 3]],
{{p1, {0, 1}}, Locator},
{{p2, {1, 2}}, Locator}]
(ugly, yes, but no time to fix it now). Typical output:
or
The idea is that you can vary the line on the left hand side of the figures you give (by clicking around the plot, which amounts to clicking on the Argand diagram...) and see the corresponding images.

Depending on what you want to do with the representations, it might sometimes be helpful to visualize the Riemann surface in 3D. Here's the surface for w=sin(z) in 3D, neatly showing the branch cuts and the different branches (same as acl's first plot, but in 3D).
ParametricPlot3D[
Evaluate[{Re#Sin[z], Im#Sin[z], y} /. z -> x + I y], {x, -2,
2}, {y, -2, 2}]

Related

Artifacts in DensityPlot (Wolfram Mathematica)

I am trying to visualize the result of numerical integration in Wolfram Mathematica using DensityPlot. But dark artifacts appear inside the circle on the graph, this is incorrect. How to fix this?
f[u_, v_]:=(1/1.2)*(1/(3.14159*0.02^2)*E^(-((x-u)^2+(y-v)^2)/0.02^2)+0.2/(3.14159*2^2)*E^(-((x-u)^2+(y-v)^2)/2^2));
i[x_, y_]:=NIntegrate[f[u, v],{u, v} \[Element] Disk[{0,0},2.5], AccuracyGoal -> 30];
DensityPlot[i[x, y], {x, -3, 3}, {y, -3, 3},ColorFunction->"SunsetColors",PlotPoints -> 20, PlotLegends -> Automatic]
Link to the image: https://postimg.cc/47MJTYj7
Well, that is not an artifact, or is it. First I'd like to point out that f is a function of u, v, x and y. So the way it is programmed is not very clean. Now to the main problem. There are two Gaussian peaks. One is very broad, the other very sharp. In many cases the numerical integral just does not get points near the sharp peak, therefore not detecting it. As the rest is smooth and easy, no subset is generated and the integral is just missing this contribution. Luckily, there is an option specifically for this. MinRecursion: NIntegrate may miss sharp peaks of integrands:.... So this works
g[x_, y_, s_] := Exp[ -( x^2 + y^2 ) / s^2] / (s^2 Pi)
f[x_, y_, u_, v_] := g[ x - u, y - v, 0.02 ] / 1.2 + 0.2 g[ x - u, y - v, 2 ]
i[x_, y_] := NIntegrate[ f[x, y, u, v], {u, v} \[Element] Disk[{0, 0}, 2.5], MinRecursion -> 5]
nn = 30;
t = Table[i[x, y], {x, -3, 3, 6/nn}, {y, -3, 3, 6/nn}];
ListDensityPlot[t, ColorFunction -> "SunsetColors", PlotLegends -> Automatic]
Takes quite some time, though. Probably, it would be better to split this up in two integrals and invest some thought on the integration boundaries.

(Mathematica) RegionPlot3D + DiscretizeRegion + ImplicitRegion does not show any tick marks for axes

Running the following snippet
region = ImplicitRegion[x - y + z == 0, {{x, -1, 1}, {y, -1, 1}, {z, -1, 1}}];
RegionPlot3D[DiscretizeRegion[region]]
Outputs
3D image of a plane
I want to have tick marks and to retain the functionality of RegionPlot3D (to be able to change the color, etc.). Any ideas?
Nothing preventing you from using all of the available options to RegionPlot3D documented here.
RegionPlot3D[DiscretizeRegion[region], PlotTheme -> "Detailed", Mesh -> None,
PlotStyle -> Directive[Red, Opacity[0.75]]]

DensityPlot3D/RegionFunction of an Equation Instead of a Function

I am trying to model in Mathematica the concentration (density) of an intersection of two graphs, eggs[x,y,z,t] and sperm[x,y,z,t]. The issue arises when one tries to implement an equation describing the graph's boundaries (sperm[x,y,z,t] == eggs[x,y,z,t]) into either DensityPlot3D or say the RegionFunction -> Function[{x,y,z,t},func] specifier. The methodology works for ContourPlot3D, however, DensityPlot3D is much more suitable for the task, as I am trying to animate the solutions and have the color of the graph be the concentration variable (4D output of sperm and egg equations).
Here is my code for the ContourPlot3D process:
In[1]:= sperm[x_,y_,z_,t_]= 1/Sqrt[4*Pi*t]*E^((-x^2-y^2-z^2)/(4*t));
eggs[x_,y_,z_,t_]=1/Sqrt[4*Pi*t]*E^((-(x+3)^2-(y+3)^2-(z+3)^2)/(4*t));
Animate[ContourPlot3D[sperm[x, y, z, t] == eggs[x, y, z, t], {x, -10, 10}, {y, -10, 10}, {z, -10, 10}], {t, 0, 10}]
The output normally crashes the system and thus cannot be uploaded here.
Here is my attempt to apply this method to the DensityPlot3D:
In[2]:= Animate[DensityPlot3D[sperm[x, y, z, t] == eggs[x, y, z, t], {x, -10, 10}, {y, -10, 10}, {z, -10, 10}], {t, 0, 10}]
The output is only a blank 3D plot.
After researching, I had found that RegionFunction (and RegionPlot3D) only seems to use inequalities, and the first argument in DensityPlot3D uses a function that is not in the form of an equation. I had tried to bypass this by doing something like
f = Solve[sperm[x, y, z, t] == eggs[x, y, z, t], {x, y, z, t}, Reals]
and inputting that variable as the first argument, but this did not help, as the result was still considered to be an equation (a complicated one at that).
So, my question is: How can I implement the equation as a boundary for DensityPlot3D?
EDIT: So it turns out the first argument can actually take in equations, as I was able to achieve an animation for s[x, y, t] == e[x, y, t].
Here is the code:
In[1]:= s[x_, y_, t_] = 1/Sqrt[4*Pi*t]*E^((-(x + 0)^2 - (y + 0)^2)/(4*t));
e[x_, y_, t_] = 1/Sqrt[4*Pi*t]*E^((-(x + 3)^2 - (y + 3)^2)/(4*t));
Animate[DensityPlot[s[x, y, t] == e[x, y, t], {x, -10, 10}, {y, -10, 10}, ColorFunction -> "TemperatureMap"], {t, 0, 10}]
I cannot figure out how to save the animation on here, and the picture is not uploading here.
Nevertheless, the problem then is simply the following: Why is DensityPlot3D a blank graph for the "4D" case?

Mathematica: Filling under an infinite function

Mathematica: Filling an infinitely deep potential well
Comment: The proper page for Mathematica questions is this one
I would like to visualize a potential well for a particle in a box in Mathematica similar to the second picture from Wikipedia here.
I have defined my function piecewise
(*Length of the box*)
L = 4;
(*Infinitly deep potential well between 0 and L*)
V[x_] := Piecewise[{
{\[Infinity], x <= 0},
{0, 0 < x < L},
{\[Infinity], L <= x}}]
and would like to obtain a plot function which gives a filled area where the potential goes to infinity.
Unfortunately my tries end up in shaded areas between the "zero region" of the potential, while I would like to have the shading in the infinity region.
Table[Plot[V[x], {x, -5, 10},
Filling -> f], {f, {Top, Bottom, Axis, 0.3}}]
The problem is that Infinity is too much for plot. So let's just give it some other big number. But to prevent it from rescaling the y axis we need to be specific with the upper plot range
Block[{\[Infinity] = 1*^1},
Plot[V[x], {x, -5, 10}, Filling -> Bottom,
PlotRange -> {Automatic, 1}]
]
Alternatively you could plot V[x]/.\[Infinity]->1*^1 instead of Block but I like Block's way better
Just give it values instead of infinity:
(*Length of the box*)L = 4;
(*Infinitly deep potential well between 0 and L*)
V[x_] := Piecewise[{{1, x <= 0}, {0, 0 < x < L}, {1, L <= x}}]
Plot[V[x], {x, -5, 10}, Filling -> Bottom]
Another way using graphic primitives:
wellLeft = 0;
leftBorder = wellLeft - 1;
rightBorder = L + 1;
wellRight = L;
top = 5;
Graphics[{
Hue[0.67, 0.6, 0.6],
Opacity[0.2],
Rectangle[{leftBorder, 0}, {wellLeft, top}],
Rectangle[{wellRight, 0}, {rightBorder, top}]
}, Axes -> True]

Some math and animation

I have a grass texture:
I use it in my 2d-game. I want to animate it by code, without any predefined animations.
The grass should interact with wind. So when the wind is stronger, the grass should stoop into need side more.
First version of animation I made using sinusoid function, but such animation is a bit ugly, because the base of the grass moves left/right like all another part of picture. And with sinusoid I'm not able to regulate stoop of the image.
Any advices?
This is what you may get easily by shifting pixels:
Although probably not very useful for you, here is a Mathematica program:
f[l_, sh_] := Module[{c = l, k = (Dimensions#l)[[1]]},
For[i = 1, i <= k, i++,
c[[i]] = RotateRight[l[[i]], IntegerPart[(k + 1 - i)/sh]]];
Return[c];]
b = ArrayPad[ImageData#a, {{40}, {40}, {0}}, {1, 1, 1}];
Export["c:\\anim.gif",
{Image#b, Image#f[b, 7],
Image#f[b, 5], Image#f[b, 3],
Image#f[b, 5], Image#f[b, 7], Image#b}, "DisplayDurations" -> .3]
Edit
But you can get a better effect by applying a circular transform:
b = Image#ArrayPad[ImageData#a, {{40, 0}, {40}, {0}}, {1, 1, 1}];
f[image_, angleMult_] := ImageForwardTransformation[image, (
fi = ArcTan[Abs[#[[2]]/(#[[1]] - .5)]];
fi1 = angleMult fi (#[[1]]^2 + #[[2]]^2)/2;
{(1/2 - Sin[fi1] #[[2]] - Cos[fi1]/2 +
Cos[fi1] #[[1]]), -Sin[fi1]/2 + Sin[fi1] #[[1]] +
Cos[fi1] #[[2]]}) &]
t = Table[f[b, x], {x, 0, .2, .02}];
t1 = Reverse#t;
Export["c:\\anim.gif", Join[t, t1], "DisplayDurations" -> .15];
Import["c:\\anim.gif", "Animation"]
You could just shift the rows, so that e.g. every 3rd row is shifted 1px to the right, beginning with the bottom.
How are you displaying the texture? When using a billboard you could manipulate the vertices of the billboard and even triangulate the billboard for more control.

Resources