In[]:=
<<"maTHEMEatica`";SetColors["Solarized"];CreateStyleSheet[];ApplyStyleSheet[];SaveStyleSheet[];
»
Creating StyleSheet based on the colorscheme:
»
,,,,,,,
In[]:=
<<"maTHEMEatica`";DeleteAll[]ApplyStyleSheet[];
Stream 08-02-2024
Stream 08-02-2024
Describe the source/sink configuration via particles.
Describe the source/sink configuration via particles.
I want to describe the motion of this texture as a bunch of orange particles moving away from the center of the image.
First, generate and draw a bunch of orange dots:
In[]:=
g[z_]=1/z;v[x_,y_]=D[ComplexExpand[Re[g[x+Iy]]],{{x,y}}];nparticles=1000;minx=miny=-2;maxx=maxy=2;minradius=0.1;maxradius=Sqrt[maxx^2+maxy^2];particlePositions=Transpose[{RandomReal[{minx,maxx},nparticles],RandomReal[{miny,maxy},nparticles]}];
In[]:=
Graphics[{RGBColor[0.92,0.5,0.1],Point@particlePositions},Background->Black]
Out[]=
Next, do a timestepping algorithm. Against my better judgement, I decided to Compile[] it. It seems like the way to go is to use Evaluate with substitution rules.
In[]:=
g[z_]=Sqrt[z^(5)-z^(1/3)];v[x_,y_]=D[ComplexExpand[Re[g[x+Iy]]],{{x,y}}];vCompiled=Compile[{x,y},Evaluate[v[x,y]],RuntimeOptions->{"EvaluateSymbolically"->False}];vCompiled[0.1,0.1]
Out[]=
{-0.110727+0.109158,-0.0305863-0.189426}
I’m clearly doing something wrong, this is way slower than uncompiled evaluation. Here’s the timing for compiled evaluation:
In[]:=
dt=0.1;nsteps=100;substeps=3;(*update[{x_,y_},dt_]={x,y}+v[x,y]dt;*)g[z_]=Log[z];v[x_,y_]=D[ComplexExpand[Re[g[x+Iy]]],{{x,y}}];timestepParticles=Compile[{{pointArray,_Real,2},{dt,_Real,0}},Table[pointArray[[i]]+dtvCompiled[pointArray[[i,1]],pointArray[[i,2]]],{i,1,Length[pointArray]}],RuntimeOptions->{"EvaluateSymbolically"->False},CompilationOptions->{"InlineExternalDefinitions"->True}];AbsoluteTiming[timestepParticles[particlePositions,dt];]
Out[]=
{0.406674,Null}
And for uncompiled:
In[]:=
g[z_]=Log[z];v[x_,y_]=D[ComplexExpand[Re[g[x+Iy]]],{{x,y}}];nparticles=1000;minx=miny=-2;maxx=maxy=2;minradius=0.1;maxradius=Sqrt[maxx^2+maxy^2];particlePositions=Transpose[{RandomReal[{minx,maxx},nparticles],RandomReal[{miny,maxy},nparticles]}];nframes=3;substeps=3;dt=0.01;update[{x_,y_},dt_]={x,y}+v[x,y]dt;stepOnce:=(particlePositions=(update[#,dt/substeps]&/@particlePositions));updateParticles:=Module[{},Do[stepOnce,substeps];]plottbl=Table[updateParticles;Graphics[{RGBColor[0.92,0.5,0.1],Point@particlePositions},Background->Black,PlotRange->{{minx,maxx},{miny,maxy}}],{frame,1,nframes}];
In[]:=
Manipulate[plottbl[[i]],{i,1,Length[plottbl],1}]
Out[]=
In[]:=
g[z_]=z^(1/3);ComplexExpand[ReIm[Conjugate[g'[x+Iy]]]]
Out[]=
,
CosArg[x+y]
2
3
3
1/3
(+)
2
x
2
y
SinArg[x+y]
2
3
3
1/3
(+)
2
x
2
y
In[]:=
g[z_]=Log[z];(*Thiswayofevaluatingvwascausingproblems*)(*v[x_,y_]=D[ComplexExpand[Re[g[x+Iy]]],{{x,y}}];*)(*Weprovedbyhandthatit'sequivalenttothisformula,whichworksbetterwithsymbolicalgebra*)v[x_,y_]=ComplexExpand[ReIm[Conjugate[g'[x+Iy]]]];nparticles=1000;minx=miny=-2;maxx=maxy=2;minradius=0.1;maxradius=Sqrt[maxx^2+maxy^2];particlePositions=Transpose[{RandomReal[{minx,maxx},nparticles],RandomReal[{miny,maxy},nparticles]}];nframes=300;substeps=10;dt=0.01;update[{x_,y_},dt_]={x,y}+v[x,y]dt;stepOnce:=(particlePositions=(update[#,dt/substeps]&/@particlePositions));updateParticles:=Module[{},Do[stepOnce;particlePositions=Function[{x,y},If[Sqrt[x^2+y^2]>maxradius,minradius{Cos[#],Sin[#]}&[RandomReal[{0,2Pi}]],{x,y}]]@@@particlePositions;,substeps];]plottbl=Table[updateParticles;Graphics[{RGBColor[0.92,0.5,0.1],Point@particlePositions},Background->Black,PlotRange->{{minx,maxx},{miny,maxy}}],{frame,1,nframes}];Export["particleMoving.gif",plottbl,ImageSize->256,"DisplayDurations"->1/30,"AnimationRepetitions"->Infinity]
Out[]=
particleMoving.gif
Okay, so obviously the distribution of orange particles isn’t stable over time,
Okay, so obviously the distribution of orange particles isn’t stable over time,
A stable distribution of particles will be described by Fokker-Planck, right?
We’ll check this next time.
Aside on the difference between equipotentials and streamlines
Aside on the difference between equipotentials and streamlines
Favorite electrostatics plot:
Favorite electrostatics plot: