Home Machine Learning Visualizing Advanced-Valued Capabilities in Python and Mathematica | by Dani Lisle | Feb, 2024

Visualizing Advanced-Valued Capabilities in Python and Mathematica | by Dani Lisle | Feb, 2024

0
Visualizing Advanced-Valued Capabilities in Python and Mathematica | by Dani Lisle | Feb, 2024

[ad_1]

Unlocking visible insights right into a tough however highly effective department of math

At present I used to be pouring by means of Advanced Variables and Analytic Capabilities by the esteemed Fornberg and Piret, making an attempt my greatest to wrap my thoughts round how complex-valued features behave. Mentally vizualization such features is additional tough since they take an actual and an imaginary enter, and outputs two elements as nicely. Due to this fact, a single 3-D plot shouldn’t be ample to see how the operate behaves. Quite, we’ve to separate such a visualization into separate plots of the imaginary and actual elements, or alternatively by magnitude and argument, or angle.

I wished to have the ability to mess around with any operate I might consider, drag and zoom round its plots, and discover it in visible element to know the way it resulted from the equation. For such a process, Wolfram Mathematica is a wonderful beginning device.

plotComplexFunction[f_]:=Module[{z,rePlot,imPlot,magPlot,phasePlot},z=x+I y;

rePlot = Plot3D[Re[f[z]],{x,-2,2},{y,-2,2},AxesLabel->{"Re(z)","Im(z)","Re(f(z))"},Mesh->None];

imPlot = Plot3D[Im[f[z]],{x,-2,2},{y,-2,2},
AxesLabel->{"Re(z)","Im(z)","Im(f(z))"},
Mesh->None];

magPlot = Plot3D[Abs[f[z]], {x, -2, 2}, {y, -2, 2},
AxesLabel -> {"Re(z)", "Im(z)", "Abs(f(z))"},
Mesh -> None,
ColorFunction -> Operate[{x, y, z}, ColorData["Rainbow"][Rescale[Arg[x + I y], {-Pi, Pi}]]],
ColorFunctionScaling -> False];

phasePlot=DensityPlot[Arg[f[z]],{x,-2,2},{y,-2,2},
ColorFunction->"Rainbow",
PlotLegends->Computerized,
AxesLabel->{"Re(z)","Im(z)"},
PlotLabel->"Section"];

GraphicsGrid[{{rePlot,imPlot},{magPlot,phasePlot}},ImageSize->800]];

f[z_]:=(1/2)*(z+1/z);

plotComplexFunction[f]
https://github.com/dreamchef/complex-functions-visualization

https://github.com/dreamchef/complex-functions-visualization

I wrote the above Mathematica code to supply a grid of plots exhibiting the operate in each methods simply described. On the highest, the imaginary and actual elements of the operate

are proven, and on the underside, and the magnitude, and the section proven in shade:

Part-Clever and Magnitude-Section Plots of f(z) from Wolfram

After taking part in round with a couple of features utilizing this code and convincing myself they made sense, I used to be keen on getting the identical performance in Python, to attach it to my different mathematical programming tasks.

I discovered a superb mission on GitHub (https://github.com/artmenlope/complex-plotting-tools) which I made a decision to make use of as a place to begin, and doubtlessly contribute to sooner or later. The repo supplied an easy interface for plotting complex-valued features in quite a lot of methods. Thanks https://github.com/artmenlope! For instance, after importing numpy, matplotlib, and the repo’s cplotting_tools module defining the operate and calling cplt.complex_plot3D(x,y,f,log_mode=False) produces the next:

Magnitude and Section Plot of f(z) from complex-plotting-tools

These are all for a similar f(z) as above. To view the side-by-side imaginary and actual elements of the operate, use cplot.plot_re_im(x,y,f,camp="twilight",contour=False,alpha=0.9:

Part-Clever Plots from complex-plotting-tools

Moreover, the library supplies different cool methods to review features, together with a stream plot:

Stream Plot of f(z) from complex-plotting-tools

The library reveals quite a lot of promise and is comparatively straightforward to make use of! It does require a pts variable to be outlined that encodes the poles and zeros of the given operate. Wolfram doesn’t require this as a result of it computes the areas of those factors beneath the hood. It could save quite a lot of effort for the consumer if complex-plotting-tools had this performance as nicely. I plan to implement that is into the module within the close to future.

Within the meantime, have enjoyable plotting with Wolfram and Python, and share your ideas and questions in feedback beneath, join with me on LinkedIn or collaborate with me on GitHub!

Except in any other case famous, all photographs had been created by the creator.

[ad_2]