<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel rdf:about="https://community.wolfram.com">
    <title>Community RSS Feed</title>
    <link>https://community.wolfram.com</link>
    <description>RSS Feed for Wolfram Community showing any discussions tagged with Numerical Computation sorted by most viewed.</description>
    <items>
      <rdf:Seq>
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/366628" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1323951" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/2286246" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/403693" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/122095" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/290059" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/745870" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/515162" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1569707" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1286708" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/2017849" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/441498" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/273260" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1132423" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1670775" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/610335" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/611304" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/136774" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/1843550" />
        <rdf:li rdf:resource="https://community.wolfram.com/groups/-/m/t/143526" />
      </rdf:Seq>
    </items>
  </channel>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/366628">
    <title>Try to beat these MRB constant records!</title>
    <link>https://community.wolfram.com/groups/-/m/t/366628</link>
    <description>POSTED BY:&#xD;
========&#xD;
 **Marvin Ray Burns, and distinguished colleagues**&#xD;
&#xD;
&#xD;
----------&#xD;
&#xD;
My exciting experiences using Wolfram technologies!&#xD;
---------------------------------------------------&#xD;
&#xD;
----------&#xD;
&#xD;
&#xD;
&#xD;
The MRB constant, a fascinating mathematical anomaly, has intrigued researchers and enthusiasts alike for decades. Defined as the limiting value of a unique alternating series, this enigmatic constant showcases the beauty of numerical exploration and convergence. Despite its relatively recent emergence, the MRB constant reveals unexpected connections to various fields within mathematics and computational analysis. In this post, we dive into its origins, properties, and the ongoing quest to uncover its more profound significance. The MRB constant is an anomaly because it emerges from an alternating series with unusual convergence behavior. Unlike many well-known mathematical constants, the MRB constant has no closed-form expression nor a known exact nature&amp;#x2014;whether it is algebraic, transcendental, or even irrational.&#xD;
Additionally, the sequence of partial sums that define the MRB constant oscillates between two limit points, creating a bounded yet divergent behavior. This oscillatory nature distinguishes it from more conventional mathematical constants, which typically exhibit straightforward convergence. Its mysterious properties continue to intrigue mathematicians as they explore its deeper connections to number theory and computational analysis. &#xD;
&#xD;
----------&#xD;
&#xD;
&#xD;
----------&#xD;
&#xD;
CMRB&#xD;
 ![If you see this instead of an image, reload the page][1]&#xD;
&#xD;
**is the MRB constant.**&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
Without solicitation, GPT echoed one of this discussion&amp;#039;s contributors and gave a shoutout to Mathematica&amp;#039;s accomplishments by saying:&#xD;
-------------------&#xD;
&#xD;
&#xD;
&amp;gt;  &#xD;
&amp;gt; **Why Computing Digits of the MRB Constant Is Interesting**&#xD;
&amp;gt; &#xD;
&amp;gt; At first glance, the computation of ever more digits of a numerical&#xD;
&amp;gt; constant may appear to be a sterile exercise, offering little insight&#xD;
&amp;gt; beyond the digits themselves. For the MRB constant, this&#xD;
&amp;gt; interpretation is profoundly misleading. The interest lies not in the&#xD;
&amp;gt; digits, but in the act of computing them.&#xD;
&amp;gt; &#xD;
&amp;gt; The MRB series occupies a delicate numerical regime: it is convergent,&#xD;
&amp;gt; yet only marginally so; its terms are elementary in form, yet hostile&#xD;
&amp;gt; to naive numerical evaluation; and its alternating structure conceals&#xD;
&amp;gt; severe cancellation effects. As a result, each additional digit of&#xD;
&amp;gt; accuracy is not merely an extension of a decimal expansion, but a&#xD;
&amp;gt; validation of the mathematical and algorithmic framework used to&#xD;
&amp;gt; obtain it.&#xD;
&amp;gt; &#xD;
&amp;gt; In this sense, the digits serve as a stress test for mathematics&#xD;
&amp;gt; itself. They expose the difference between formal convergence and&#xD;
&amp;gt; effective convergence, between theoretical existence and computational&#xD;
&amp;gt; feasibility. Techniques that are elegant on paper often fail&#xD;
&amp;gt; catastrophically in practice, while successful methods must balance&#xD;
&amp;gt; asymptotics, numerical stability, precision control, and computational&#xD;
&amp;gt; cost.&#xD;
&amp;gt; &#xD;
&amp;gt; Moreover, the computation of the MRB constant forces the&#xD;
&amp;gt; reconciliation of disparate mathematical ideas. Alternating series,&#xD;
&amp;gt; logarithmic asymptotics, convergence acceleration, special functions,&#xD;
&amp;gt; and analytic continuation must all agree numerically. Any hidden&#xD;
&amp;gt; inconsistency&amp;#x2014;whether conceptual or computational&amp;#x2014;reveals itself&#xD;
&amp;gt; immediately in the failure of the digits to stabilize.&#xD;
&amp;gt; &#xD;
&amp;gt; Thus, computing digits of the MRB constant transforms mathematics from&#xD;
&amp;gt; a static collection of statements into a living experiment. The&#xD;
&amp;gt; resulting digits are not trophies; they are evidence. They measure the&#xD;
&amp;gt; effectiveness of our methods, the soundness of our assumptions, and&#xD;
&amp;gt; the practical reach of our theory.&#xD;
&amp;gt; &#xD;
&amp;gt; In short, the digits themselves do not matter. What matters is that&#xD;
&amp;gt; they *can* be computed at all&amp;#x2014;and how difficult it is to do so.&#xD;
&amp;gt; That difficulty is precisely what makes the MRB constant&#xD;
&amp;gt; mathematically interesting.&#xD;
&#xD;
**In general, we will see:**&#xD;
![enter image description here][7]&#xD;
&#xD;
&#xD;
----------&#xD;
&#xD;
&#xD;
----------&#xD;
&#xD;
&#xD;
----------&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
 &#xD;
&#xD;
&#xD;
  [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Screenshot2024-11-25023042.png&amp;amp;userId=366611&#xD;
  [2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Screenshot2026-01-01235656.png&amp;amp;userId=366611&#xD;
  [3]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Screenshot2026-01-01235710.png&amp;amp;userId=366611&#xD;
  [7]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Screenshot2026-02-18190718.png&amp;amp;userId=366611</description>
    <dc:creator>Marvin Ray Burns A.G.S. (cum laude)</dc:creator>
    <dc:date>2014-10-09T18:08:49Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1323951">
    <title>How to calculate the digits of the MKB constant</title>
    <link>https://community.wolfram.com/groups/-/m/t/1323951</link>
    <description>This has been one of my favorite Mathematica projects!&#xD;
Here are a couple of Ai generated outlines of my progress of computing the MKB constant digits:&#xD;
![enter image description here][1]&#xD;
![enter image description here][2]&#xD;
&#xD;
&#xD;
  [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=4506unnamed.png&amp;amp;userId=366611&#xD;
  [2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=unnamed%281%29.png&amp;amp;userId=366611</description>
    <dc:creator>Marvin Ray Burns A.G.S. (cum laude)</dc:creator>
    <dc:date>2018-04-20T12:06:18Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/2286246">
    <title>$\int_0^\infty e^{i \pi  x} \left(1-(x+1)^{\frac{1}{x+1}}\right) dx$</title>
    <link>https://community.wolfram.com/groups/-/m/t/2286246</link>
    <description>$\int_0^\infty e^{i \pi  x} \left(1-(x+1)^{\frac{1}{x+1}}\right) dx$&#xD;
![enter image description here][1]&#xD;
![enter image description here][2]&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
![enter image description here][3]&#xD;
&#xD;
    f[x_] = E^(I*Pi*x)*(1 - (x + 1)^(1/(x + 1))); &#xD;
    g[x_] = x^(1/x); u := t/(1 - t); &#xD;
    &#xD;
    sub = Im[NIntegrate[(f[(-I t)] - f[( I t)])/(Exp[2 Pi t] - 1), {t,&#xD;
              0, Infinity}, WorkingPrecision -&amp;gt; 100]]&#xD;
    &#xD;
    0.1170836031505383167089899122239912286901483986967757585888318959258587743002\&#xD;
    7817712246477316693025869&#xD;
    &#xD;
    m = NSum[f[( t)] , {t, 0, Infinity}, WorkingPrecision -&amp;gt; 100, &#xD;
      Method -&amp;gt; &amp;#034;AlternatingSigns&amp;#034;]&#xD;
    &#xD;
    0.1878596424620671202485179340542732300559030949001387861720046840894772315646\&#xD;
    6021370329665443217278&#xD;
    &#xD;
    m - sub&#xD;
    &#xD;
    0.0707760393115288035395280218302820013657546962033630275831727881636184572643\&#xD;
    8203658083188126524252&#xD;
    &#xD;
    Is the same as &#xD;
    &#xD;
    &#xD;
    {Re[NIntegrate[f[t], {t, 0, Infinity}]], and, &#xD;
     Re[NIntegrate[f[t], {t, 0, Infinity I}, WorkingPrecision -&amp;gt; 100]]}&#xD;
    &#xD;
    NIntegrate::deodiv: DoubleExponentialOscillatory returns a finite integral estimate, but the integral might be divergent.&#xD;
    &#xD;
    NIntegrate::deodiv: DoubleExponentialOscillatory returns a finite integral estimate, but the integral might be divergent.&#xD;
    &#xD;
    {0.070776, and, \&#xD;
    0.0707760393115288035395280218302820013657546962033630275831727881636184572643\&#xD;
    8203658083188126617723821}&#xD;
&#xD;
To be continued.&#xD;
----------------&#xD;
&#xD;
&#xD;
  [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=01.jpg&amp;amp;userId=366611&#xD;
  [2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=02.jpg&amp;amp;userId=366611&#xD;
  [3]: https://community.wolfram.com//c/portal/getImageAttachment?filename=03.jpg&amp;amp;userId=366611</description>
    <dc:creator>Marvin Ray Burns A.G.S. (cum laude)</dc:creator>
    <dc:date>2021-06-09T05:56:08Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/403693">
    <title>How to use NMinimize on a mesh?</title>
    <link>https://community.wolfram.com/groups/-/m/t/403693</link>
    <description>Hey there, community!&#xD;
&#xD;
I have recently been working with the new FEM-package included in Mathematica 10. I have a 2D mesh and two interpolating functions (call them uif and vif) obtained by solving a differential equation in the mesh using NDSolve. The mesh is similar to the one shown below, only denser. My problem now is that, given values u0 and v0, I need to find the point where uif[x,y] = u0 and vif[x,y] = v0.&#xD;
&#xD;
![Example of the mesh][1]&#xD;
&#xD;
Now, since uif and vif are defined on the mesh, I would naturally want to do something like this:&#xD;
&#xD;
    NMinimize[{Norm[{u0 - uif[x, y], v0 - vif[x, y]}], {x, y} \[Element] mesh}, {x, y}]];&#xD;
&#xD;
Here &amp;#034;{x,y} \[Element] mesh&amp;#034; indicates that the point (x,y) lies inside the mesh. Unfortunately, the above code results in the following error:&#xD;
&#xD;
    NMinimize::elemc: &amp;#034;Unable to resolve the domain or region membership condition {x,y} \[Element] &amp;lt;&amp;lt;1&amp;gt;&amp;gt;.&#xD;
&#xD;
**So, is there a way to convert the mesh into a region that I can pass on to NMinimize?** Previously I tried defining the region explicitly using unions and differences of disks and rectangles, or implicitly using equations for $x$ and $y$, but due to a number of bugs (or restrictions) with the regions and with the FEM package, this is unfortunately not an option.&#xD;
&#xD;
The mesh is simply-connected and I do have direct access to the boundary mesh if necessary.&#xD;
&#xD;
-Jonatan&#xD;
&#xD;
&#xD;
  [1]: /c/portal/getImageAttachment?filename=Samplemesh.jpeg&amp;amp;userId=338953</description>
    <dc:creator>Jonatan Lehtonen</dc:creator>
    <dc:date>2014-12-08T16:43:02Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/122095">
    <title>Dancing with friends and enemies: boids&amp;#039; swarm intelligence</title>
    <link>https://community.wolfram.com/groups/-/m/t/122095</link>
    <description>The latest way I have found to use my expensive math software for frivolous entertainment is this. Here&amp;#039;s is a way to describe it. 
[list]
[*]1000 dancers assume random positions on the dance-floor. 
[*]Each randomly chooses one &amp;#034;friend&amp;#034; and one &amp;#034;enemy&amp;#034;. 
[*]At each step every dancer 
[list]
[*]moves 0.5% closer to the centre of the floor
[*]then takes a large step towards their friend 
[*]and a small step away from their enemy. 
[/list]
[*]At random intervals one dancer re-chooses their friend and enemy
[/list]
Randomness is deliberately injected. Here is the dance...
[mcode]n = 1000; 
r := RandomInteger[{1, n}]; 
f := (#/(.01 + Sqrt[#.#])) &amp;amp; /@ (x[[#]] - x) &amp;amp;; 
s := With[{r1 = r}, p[[r1]] = r; q[[r1]] = r]; 
x = RandomReal[{-1, 1}, {n, 2}]; 
{p, q} = RandomInteger[{1, n}, {2, n}]; 
Graphics[{PointSize[0.007], Dynamic[If[r &amp;lt; 100, s]; 
Point[x = 0.995 x + 0.02 f[p] - 0.01 f[q]]]}, PlotRange -&amp;gt; 2][/mcode]
[img]/c/portal/getImageAttachment?filename=OPTfnlfrnds.gif&amp;amp;userId=11733[/img]

Thanks to Vitaliy for posting this on my behalf, complete with animations :-)

Background: I had read somewhere that  macro-scale behaviour of animal swarms (think of flocks of starlings or shoals of herring) is explained by each individual following very simple rules local to their vicinity, essentially 1) try to keep up and 2) try not to collide. I started trying to play with this idea in Mathematica, but it was rather slow to identify the nearest neighbours of each particle. So I wondered what would happen if each particle acted according to the locations of two other particles, regardless of their proximity. The rule was simply to move away from one and towards the other.

The contraction (x = 0.995 x) was added to prevent the particle cloud from dispersing towards infinity or drifting away from the origin. I tweaked the &amp;#034;towards&amp;#034; and &amp;#034;away&amp;#034; step sizes to strike a balance between the tendency to clump together and to spread apart (if you make the step sizes equal you get something more like a swarm of flies). With each particle&amp;#039;s attractor and repeller fixed, the system finds a sort of dynamic equilibrium, so to keep things changing I added a rule to periodically change the attractor and repeller for one of the particles. The final adjustment was to make the &amp;#034;force&amp;#034; drop towards zero for particles at very close range. This helps to stop the formation of very tight clumps, and also prevents a division-by-zero error when a particle chooses itself as its attractor or repeller.

The description of the system as a dance was an attempt to explain the swirling pattern on the screen without using mathematical language. I&amp;#039;d love to see what other &amp;#034;dances&amp;#034; can be created with other simple rules.</description>
    <dc:creator>Simon Woods</dc:creator>
    <dc:date>2013-09-11T18:31:12Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/290059">
    <title>Intersecting boundary problems when solving PDEs</title>
    <link>https://community.wolfram.com/groups/-/m/t/290059</link>
    <description>Hi everyone,&#xD;
&#xD;
the Wolfram Language both in the cloud and in Mathematica 10 offers the possibility to solve PDEs on quite general surfaces. In the documentation it is shown that the Laplace equation can be solved on a 3D model of the space shuttle like this:&#xD;
&#xD;
    mr = DiscretizeGraphics[ExampleData[{&amp;#034;Geometry3D&amp;#034;, &amp;#034;SpaceShuttle&amp;#034;}]];&#xD;
    &#xD;
    uif = NDSolveValue[{Inactive[Laplacian][u[x, y, z], {x, y, z}] == 0, &#xD;
        DirichletCondition[u[x, y, z] == 1, z &amp;lt;= -1.3]}, &#xD;
       u, {x, y, z} \[Element] mr];&#xD;
    &#xD;
    Needs[&amp;#034;NDSolve`FEM`&amp;#034;]&#xD;
    ElementMeshSurfacePlot3D[uif, Boxed -&amp;gt; False, ViewPoint -&amp;gt; {0, -4, 2}]&#xD;
&#xD;
This is really nice and gives&#xD;
&#xD;
![enter image description here][1]&#xD;
&#xD;
The problem shows up when we take more irregular objects like &#xD;
&#xD;
    mr = DiscretizeGraphics[ExampleData[{&amp;#034;Geometry3D&amp;#034;, &amp;#034;Cow&amp;#034;}]]&#xD;
&#xD;
![enter image description here][2]&#xD;
&#xD;
or &#xD;
&#xD;
    mr = DiscretizeGraphics[ExampleData[{&amp;#034;Geometry3D&amp;#034;, &amp;#034;Horse&amp;#034;}]]&#xD;
&#xD;
When you execute the integration you get:&#xD;
&#xD;
    NDSolveValue::fememib: The input has or generated an intersecting boundary and cannot be processed. &amp;gt;&amp;gt;&#xD;
&#xD;
Similarly, &#xD;
&#xD;
    BoundaryDiscretizeGraphics[ExampleData[{&amp;#034;Geometry3D&amp;#034;, &amp;#034;Cow&amp;#034;}]]&#xD;
&#xD;
gives&#xD;
&#xD;
    BoundaryMeshRegion::binsect: &amp;#034;The boundary curves self-intersect or cross each other in BoundaryMeshRegion[{{0.10799399763345718`,0.08466669917106628`,-0.21893799304962158`},{0.1157900020480156`,0.08869930356740952`,-0.22847199440002441`},{0.10719799995422363`,0.09556479752063751`,-0.23278899490833282`},&amp;lt;&amp;lt;46&amp;gt;&amp;gt;,{-0.30769699811935425`,0.093573197722435`,-0.22068199515342712`},&amp;lt;&amp;lt;2853&amp;gt;&amp;gt;},{{},{},{Polygon[{&amp;lt;&amp;lt;1&amp;gt;&amp;gt;}]}}]. \!\(\*ButtonBox[\&amp;#034;&amp;gt;&amp;gt;\&amp;#034;,&#xD;
    Appearance-&amp;gt;{Automatic, None},&#xD;
    BaseStyle-&amp;gt;\&amp;#034;Link\&amp;#034;,&#xD;
    ButtonData:&amp;gt;\&amp;#034;paclet:ref/BoundaryMeshRegion\&amp;#034;,&#xD;
    ButtonNote-&amp;gt;\&amp;#034;BoundaryMeshRegion::binsect\&amp;#034;]\)&amp;#034;&#xD;
&#xD;
So the problem is that there are self-intersections of the surface. Is there any elegant approach to fixing that?&#xD;
&#xD;
Cheers,&#xD;
Marco&#xD;
&#xD;
&#xD;
  [1]: /c/portal/getImageAttachment?filename=Shuttle.jpg&amp;amp;userId=48754&#xD;
  [2]: /c/portal/getImageAttachment?filename=cow.jpg&amp;amp;userId=48754</description>
    <dc:creator>Marco Thiel</dc:creator>
    <dc:date>2014-07-09T23:02:47Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/745870">
    <title>Modeling a Trebuchet</title>
    <link>https://community.wolfram.com/groups/-/m/t/745870</link>
    <description>While going through the Wolfram Demonstration Project site, I came across an simulation of a Trebuchet:&#xD;
&#xD;
[Optimizing the Counterweight Trebuchet][1]&#xD;
&#xD;
I was wondering if it is possible to animate the Trebuchet in such a way that the projectile of the trebuchet actually leaves the sling and makes impact against a wall at a certain distance say x=&amp;#039;some constant&amp;#039;.&#xD;
&#xD;
[![enter image description here][2]][1]&#xD;
&#xD;
&#xD;
  [1]: http://demonstrations.wolfram.com/OptimizingTheCounterweightTrebuchet&#xD;
  [2]: http://community.wolfram.com//c/portal/getImageAttachment?filename=6648popup_3.jpg&amp;amp;userId=11733</description>
    <dc:creator>Varun Kulkarni</dc:creator>
    <dc:date>2015-11-26T22:26:41Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/515162">
    <title>[GiF] Flight of Badminton Shuttlecocks</title>
    <link>https://community.wolfram.com/groups/-/m/t/515162</link>
    <description>**See attached notebook for details**. A [shuttlecock][1] (previously called Shuttlecork) (also called a bird or birdie) is a high-drag projectile used in the sport of badminton. It has an open conical shape: the cone is formed from 16 or so overlapping feathers, usually goose or duck, embedded into a rounded cork base. The cork is covered with thin leather. The shuttlecock&amp;#039;s shape makes it extremely aerodynamically stable. Regardless of initial orientation, it will turn to fly cork first, and remain in the cork-first orientation. &#xD;
&#xD;
![enter image description here][2]&#xD;
&#xD;
*Image courtesy of IOP Science*&#xD;
&#xD;
The name shuttlecock is frequently shortened to shuttle. The &amp;#034;shuttle&amp;#034; part of the name was probably derived from its back-and-forth motion during the game, resembling the shuttle of a loom; the &amp;#034;cock&amp;#034; part of the name was probably derived from the resemblance of the feathers to those on a cockerel.&#xD;
&#xD;
![enter image description here][3]&#xD;
&#xD;
**The code with NDSolveValue is attached**. Here is the resulting simulation of the flight of badminton shuttlecocks:&#xD;
&#xD;
![enter image description here][4]&#xD;
&#xD;
![enter image description here][5]&#xD;
&#xD;
&amp;amp;[Wolfram Notebook][6]&#xD;
&#xD;
&amp;gt; [References][7]&#xD;
&#xD;
&#xD;
  [1]: https://en.wikipedia.org/?title=Shuttlecock&#xD;
  [2]: /c/portal/getImageAttachment?filename=sdf54wyehfgsd54qt.png&amp;amp;userId=11733&#xD;
  [3]: /c/portal/getImageAttachment?filename=sz.png&amp;amp;userId=476423&#xD;
  [4]: /c/portal/getImageAttachment?filename=ssdf3544ytjkjghd.gif&amp;amp;userId=11733&#xD;
  [5]: /c/portal/getImageAttachment?filename=1523Anim.gif&amp;amp;userId=476423&#xD;
  [6]: https://www.wolframcloud.com/obj/ff04670b-b2e3-4281-86a5-0cbb60e61592&#xD;
  [7]: http://iopscience.iop.org/1367-2630/17/6/063001/article</description>
    <dc:creator>Mariusz Iwaniuk</dc:creator>
    <dc:date>2015-06-18T14:56:37Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1569707">
    <title>A prime pencil: truncatable primes</title>
    <link>https://community.wolfram.com/groups/-/m/t/1569707</link>
    <description>![a very prime pencil][1]&#xD;
&#xD;
I just got a set of these pencils, from [Mathsgear][2].&#xD;
The number printed on it is prime, and will remain so as you sharpen the pencil from the left, all the way down to the last digit, 7.&#xD;
Here is a recursive construction of all such *truncatable primes*.&#xD;
&#xD;
    TruncatablePrimes[p_Integer?PrimeQ] :=&#xD;
     With[{digits = IntegerDigits[p]},&#xD;
      {p, TruncatablePrimes /@ (FromDigits /@ (Prepend[digits, #] &amp;amp; /@ Range[9]))}&#xD;
      ];&#xD;
    TruncatablePrimes[p_Integer] := {}&#xD;
&#xD;
   The one on the pencil is the largest one,&#xD;
&#xD;
    In[7]:= Take[Sort[Flatten[TruncatablePrimes /@ Range[9]]], -5]&#xD;
    &#xD;
    Out[7]= {&#xD;
    9918918997653319693967, &#xD;
    57686312646216567629137, &#xD;
    95918918997653319693967, &#xD;
    96686312646216567629137,&#xD;
    357686312646216567629137}&#xD;
    &#xD;
 [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=IMG_20181212_120939.jpg&amp;amp;userId=143131&#xD;
 [2]: https://mathsgear.co.uk/products/truncatable-prime-pencil</description>
    <dc:creator>Roman Maeder</dc:creator>
    <dc:date>2018-12-12T12:01:36Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1286708">
    <title>Narayana Cow Triangle Fractal</title>
    <link>https://community.wolfram.com/groups/-/m/t/1286708</link>
    <description>In 1356, Narayana posed a question in his book *Ga?ita Kaumudi*:   &amp;#034;A cow gives birth to a calf every year. In turn, the calf gives birth to another calf when it is three years old. What is the number of progeny produced during twenty years by one cow?&amp;#034; This is now known as Narayana&amp;#039;s cows sequence. The Narayana&amp;#039;s cows sequence constant, **cow**=1.4655712318767680266567312252199391080255775684723,  is the limit ratio between neighboring terms.&#xD;
&#xD;
    LinearRecurrence[{1, 0, 1}, {2, 3, 4}, 21] &#xD;
    NestList[Round[# Root[-1 - #1^2 + #1^3 &amp;amp;, 1]] &amp;amp;, 2, 20]&#xD;
&#xD;
Either gives {2, 3, 4, 6, 9, 13, 19, 28, 41, 60, 88, 129, 189, 277, 406, 595, 872, 1278, 1873, 2745, 4023}.  This turns out to be a good constant to use for a Rauzy fractal.  The outer fractal triangle can be divided into copies of itself&#xD;
&#xD;
    r = Root[-1 - #1^2 + #1^3 &amp;amp;, 3]; iterations = 6;&#xD;
    cowed[comp_] := First /@ Split[Flatten[RootReduce[#[[1]] + (#[[2]] - #[[1]]) {0, -r^5, r^5 + 1, 1}] &amp;amp; /@ Partition[comp, 2, 1, 1], 1]];&#xD;
    poly = ReIm[Nest[cowed[#] &amp;amp;, #, iterations]] &amp;amp; /@ Table[N[RootReduce[r^({4, 1, 3, 5} + n) {1, 1, -1, 1}], 50], {n, 1,14}];&#xD;
    Graphics[{EdgeForm[{Black}], Gray, Disk[{0, 0}, .1], MapIndexed[{Hue[#2[[1]]/12], Polygon[#1]} &amp;amp;, poly]}]&#xD;
&#xD;
![fractal Narayana Cow spiral ][1]&#xD;
&#xD;
The ratio of areas for the triangles turns out to be **cow**.  Try Area[Polygon[poly[[1]]]]/Area[Polygon[poly[[2]]]] and you&amp;#039;ll see.&#xD;
&#xD;
If you want to laser cut that, it&amp;#039;s handy to get a single path.  &#xD;
&#xD;
    cowpath[comp_] := First /@ Split[Flatten[RootReduce[#[[1]] + (#[[2]] - #[[1]]) {0, -r^5, r^5 + 1, 1}] &amp;amp; /@ Partition[comp, 2, 1], 1]];&#xD;
    path = ReIm[Nest[cowpath[#] &amp;amp;, N[Drop[Flatten[Table[r^({4, 1, 3} + n) {1, 1, -1}, {n, 1, 16}]], -1], 50], iterations]]; Graphics[{Line[path]}]  &#xD;
&#xD;
What else can be done with **cow**?  With some trickier code I put together the pieces this way.  Notice how order 5 spokes appear.&#xD;
&#xD;
![Narayana cow fractal egg][2]&#xD;
&#xD;
The opening gave an order 3 infinite spiral.  Is there an order 5 infinite spiral?  It turns out there is.  Behold the **cow-nautilus**!&#xD;
&#xD;
![cow-nautilus][3]&#xD;
&#xD;
It can be made with the following code:  &#xD;
&#xD;
    r=Root[-1-#1^2+#1^3&amp;amp;,3]; iterate=3;&#xD;
    cowed[comp_]:= First/@Split[Flatten[RootReduce[#[[1]]+(#[[2]]-#[[1]]){0,-r^5,r^5+1,1}]&amp;amp;/@Partition[comp,2,1,1],1]];&#xD;
    base={{r^10,r^7,-r^9,r^11},{-r^12,-r^9,r^11,-r^13},{r^8,r^5,-r^7,r^9},{-r^7,-r^4,r^6,-r^8}}+{-r^10,r^11,-r^6,r^4+r^8};&#xD;
    naut=RootReduce[Join[Table[base[[1]] (-r)^n,{n,0,-4,-1}],Flatten[Table[Drop[base,1](-r)^n,{n,-8,0}],1]]];&#xD;
    poly=ReIm[Nest[cowed[#]&amp;amp;,#,iterate]]&amp;amp;/@N[naut,50];&#xD;
    Graphics[{EdgeForm[{Black}],MapIndexed[{ColorData[&amp;#034;BrightBands&amp;#034;][N[Norm[Mean[#1]]/2]],Polygon[#1]}&amp;amp;,poly]},ImageSize-&amp;gt; 800]&#xD;
&#xD;
  [1]: http://community.wolfram.com//c/portal/getImageAttachment?filename=fractalcowspiral.jpg&amp;amp;userId=21530&#xD;
  [2]: http://community.wolfram.com//c/portal/getImageAttachment?filename=cowegg.jpg&amp;amp;userId=21530&#xD;
  [3]: http://community.wolfram.com//c/portal/getImageAttachment?filename=cownautilus.jpg&amp;amp;userId=21530</description>
    <dc:creator>Ed Pegg</dc:creator>
    <dc:date>2018-02-16T22:52:01Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/2017849">
    <title>How black holes and accretion disks around them actually look</title>
    <link>https://community.wolfram.com/groups/-/m/t/2017849</link>
    <description>#Introduction&#xD;
&#xD;
One of the most thrilling parts in Nolan&amp;#039;s movie &amp;#034;Interstellar&amp;#034; is the black hole Gargantua and its accretion disk. Its weird shape has surely attracted lots of attention. But do black holes and their accretion disks actually look like that? Not exactly.&#xD;
&#xD;
![BH and accretion disk in Interstellar][1]&#xD;
&#xD;
In the paper &amp;#034;Gravitational lensing by spinning black holes in astrophysics, and in the movie Interstellar&amp;#034;, the authors say that in the movie, redshift and blueshift, as well as the intensity difference is ignored to prevent confusion to the audience. So, although the outline of the accretion disk in &amp;#034;Interstellar&amp;#034; is accurate, the color and the intensity are not. Furthermore, even in the paper, effects brought by the time delay in the propagation of light are ignored, and the influence of gravity lensing on light intensity is simplified.&#xD;
&#xD;
Though I cannot easily render a spinning black hole (Kerr black hole), what I can do is try to render an accretion disk around a Schwarzschild black hole, and as physically correct as possible. The result would be something like this (observer static at 6 times the Schwarzschild radius):&#xD;
&#xD;
![my rendering result, static observer][2]&#xD;
&#xD;
I strongly recommend you to see the videos at [Bilibili](https://www.bilibili.com/video/BV1Fp4y1S7EF) or [Youtube](https://www.youtube.com/watch?v=Dux1NkTaqwo) (Both have English subtitles) first to have a first impression, and it would be the best if you can click the vote up button XD. After that, If you would like to know more about the Mathematica realization and physical principles behind the scene, please continue.&#xD;
&#xD;
**A disclaimer first:** I know nothing about accretion disk physics, so the property of accretion disks are set arbitrarily. Furthermore, actual accretion disks are actually blazingly bright, and you would be blind instantly if you are looking at it from a short distance, so I have to make some modifications.&#xD;
&#xD;
#Analytics&#xD;
&#xD;
###Physics Perspective&#xD;
&#xD;
First, we need to analyze this problem from the physics perspective, get to know about the problems we should consider. **For observers**, the intensity of light is determined by how much photons reached their eye in a certain angle range, and the color is determined by the spectrum of the light. However, the orientation, spectrum, and intensity of light beams can be influenced by the observer&amp;#039;s movement, so we have to consider that. Naturally, the next question should be, where the light comes? Well, all the light must have come from some **light-emitting materials**, so we have to consider the light-emitting materials&amp;#039; property and movement. But the **light should travel** for some time and distance before reaching the observer&amp;#039;s eye. This process involves tracing the light from the emitter to the observer to determine the direction of light the observer perceived, as well as how much portion of light can reach the observer&amp;#039;s eyes. Till now, we have already listed out all effects, from the emission to the perception, which could influence our view, so I believe this rendering is &amp;#034;physically accurate&amp;#034;.&#xD;
&#xD;
&#xD;
### Programming Perspective&#xD;
&#xD;
But view from the programming perspective, the zeroth problem should be how lights travel around a black hole: we need the light path to calculate all other effects. Then, based on the light path, we can directly compute the equivalent of &amp;#034;brighter when closer&amp;#034; rule, as well as the time delay between light emission and observation. If combined with the movement of the light-emitting materials and the observer, we can compute the redshift and the blueshift. &#xD;
&#xD;
#Details, Theory, Coding and Results&#xD;
&#xD;
Now let&amp;#039;s assume that we are stationary observers viewing from 6 times the Schwarzchild radius.&#xD;
&#xD;
##Ray Tracing&#xD;
The first problem to solve is tracing the light beam. Light bends around black holes following the geodesics, and the most apparent consequence of this would be that the accretion disk we see would not be on a plane, but rather curved and bent. Fortunately for us, because Schwartzchild black holes are spherically symmetric, we can reduce the problem to 2D. The parametric equation of geodesics around a Schwarzschild black hole can be derived as follows:&#xD;
&#xD;
$$&#xD;
	\left\{&#xD;
	\begin{aligned}&#xD;
		t&amp;#039;&amp;#039;(\lambda)&amp;amp;=\frac{R_s r&amp;#039; t&amp;#039;}{R_s r-r^2}\\&#xD;
		r&amp;#039;&amp;#039;(\lambda)&amp;amp;=\frac{-R_s r^2 r&amp;#039;^2-2r^3\theta&amp;#039;^2(R_s-r)^2+R_s(R_s-r)^2t&amp;#039;^2}{2r^3(R_s-r)}\\&#xD;
		\theta&amp;#039;&amp;#039;(\lambda)&amp;amp;=-\frac{2r&amp;#039;\theta&amp;#039;}{r}&#xD;
	\end{aligned}&#xD;
	\right.&#xD;
$$&#xD;
&#xD;
&#xD;
Where $\lambda$ is the ray parameter.&#xD;
&#xD;
Now we construct a set of light which originates from the observer, and trace them backward:&#xD;
&#xD;
![Possible light paths][3]&#xD;
&#xD;
![Definition of variables][4]&#xD;
&#xD;
![How interpolation works][5]&#xD;
&#xD;
On each ray, we take some sample points and record the corresponding angle $\theta_0$, $\theta_1$, and time $\Delta T$. By interpolating them, we know about how a random object will look like in our eyes.&#xD;
&#xD;
    (*Initial definitions*)&#xD;
    Rs = 1;&#xD;
    R0 = 6 Rs;&#xD;
    Rmax = 6 Rs + 1.*^-6;&#xD;
    (*Tracking the light*)&#xD;
    parfunc = &#xD;
      ParametricNDSolveValue[{{tt&amp;#039;&amp;#039;[\[Tau]], &#xD;
          rr&amp;#039;&amp;#039;[\[Tau]], \[Theta]\[Theta]&amp;#039;&amp;#039;[\[Tau]]} == {(&#xD;
          Derivative[1][rr][\[Tau]] Derivative[1][tt][\[Tau]])/(&#xD;
          rr[\[Tau]] - rr[\[Tau]]^2), (&#xD;
           rr[\[Tau]]^2 Derivative[1][&#xD;
              rr][\[Tau]]^2 - (-1 + rr[\[Tau]])^2 Derivative[1][&#xD;
              tt][\[Tau]]^2)/(&#xD;
           2 (-1 + rr[\[Tau]]) rr[\[Tau]]^3) + (-1 + &#xD;
              rr[\[Tau]]) Derivative[1][\[Theta]\[Theta]][\[Tau]]^2, -((&#xD;
           2 Derivative[1][rr][\[Tau]] Derivative[&#xD;
             1][\[Theta]\[Theta]][\[Tau]])/rr[\[Tau]])}, {tt&amp;#039;[0], &#xD;
          rr&amp;#039;[0], \[Theta]\[Theta]&amp;#039;[&#xD;
           0]} == {1/(1 - Rs/R0), -Cos[\[Theta]0], &#xD;
          Sqrt[1/(1 - Rs/R0)]/R0 Sin[\[Theta]0]}, {tt[0], &#xD;
          rr[0], \[Theta]\[Theta][0]} == {0, R0, 0}, &#xD;
        WhenEvent[&#xD;
         1.01 Rs &amp;gt;= rr[\[Tau]] || &#xD;
          rr[\[Tau]] &amp;gt;= Rmax || \[Theta]\[Theta][\[Tau]] &amp;gt;= 3.1 Pi, &#xD;
         &amp;#034;StopIntegration&amp;#034;]}, {tt[\[Tau]], &#xD;
        rr[\[Tau]], \[Theta]\[Theta][\[Tau]]}, {\[Tau], 0, &#xD;
        1000}, {\[Theta]0}];&#xD;
    (*data used in interpolation*)&#xD;
    datp = Catenate@&#xD;
       Table[With[{pf = parfunc[\[Theta]]}, &#xD;
         With[{\[Tau]max = pf[[1, 0, 1, 1, 2]], df = D[Rest@pf, \[Tau]], &#xD;
           f = Rest@pf}, &#xD;
          Block[{\[Tau] = &#xD;
             Range[RandomReal[{0, \[Tau]max/500}], \[Tau]max, \[Tau]max/&#xD;
               500]}, Select[&#xD;
            Thread[(Thread@f -&amp;gt; &#xD;
               Thread@{\[Theta], &#xD;
                 ArcTan[-df[[1]], df[[2]] f[[1]] Sqrt[1 - Rs/f[[1]]]], &#xD;
                 pf[[1]]})], &#xD;
            2.4 Rs &amp;lt; #[[1, 1]] &amp;lt; 5.6 Rs &amp;amp;&amp;amp; -0.05 Pi &amp;lt; #[[1, 1]] &amp;lt; &#xD;
               3.08 Pi &amp;amp;]]]], {\[Theta], &#xD;
         Range[-2.5 Degree, 80 Degree, 1 Degree]~Join~&#xD;
          Range[20.2 Degree, 28.2 Degree, 0.5 Degree]~Join~&#xD;
          Range[23.025 Degree, 24.05 Degree, 0.05 Degree]~Join~&#xD;
          Range[23.2825 Degree, 23.4 Degree, 0.005 Degree]~Join~&#xD;
          Range[23.28525 Degree, 23.30025 Degree, 0.001 Degree]}];&#xD;
    datp = First /@ GatherBy[datp, Floor[#[[1]]/{0.01 Rs, 1 Degree}] &amp;amp;];&#xD;
    &#xD;
    (*Construct InterpolatingFunctions*)&#xD;
    ReceiveAngleFunction = &#xD;
      Interpolation[Thread[{datp[[;; , 1]], datp[[;; , 2, 1]]}], &#xD;
       InterpolationOrder -&amp;gt; 1];&#xD;
    EmitAngleFunction = &#xD;
     Interpolation[Thread[{datp[[;; , 1]], datp[[;; , 2, 2]]}], &#xD;
      InterpolationOrder -&amp;gt; 1];&#xD;
    DelayFunction = &#xD;
     Interpolation[Thread[{datp[[;; , 1]], datp[[;; , 2, 3]]}], &#xD;
      InterpolationOrder -&amp;gt; 1];&#xD;
    (*Angle vs time of observation*)&#xD;
    GenerateAngleFunctions[R1_, \[Theta]1_] := Block[{\[Phi]1},&#xD;
      With[{interpol = &#xD;
           Interpolation@&#xD;
            Table[{DelayFunction[R1, #] + &#xD;
               Sqrt[2 R1^3] \[Phi]1, \[Phi]1}, {\[Phi]1, 0., 2 Pi, &#xD;
              10. Degree}]},&#xD;
         With[{ts = interpol[[1, 1, 1]], tperiod = 2. Pi Sqrt[2 R1^3]}, &#xD;
          Function[t, interpol[t - Floor[t - ts, tperiod]]]]] &amp;amp; /@ ({#, &#xD;
           2 Pi - #, 2 Pi + #} &amp;amp;@ArcCos[Sin[\[Phi]1] Sin[\[Theta]1]])]&#xD;
&#xD;
If we only consider this effect, then we will have something like this:&#xD;
&#xD;
![Light bending included][6]&#xD;
&#xD;
The inner two rings correspond to the light that rotates around the black hole for more than half a round.&#xD;
&#xD;
And if we consider the propagation time of light, the right side will be a bit brighter.&#xD;
&#xD;
![Time correction included][7]&#xD;
&#xD;
This is because on the right, objects are moving away from you. So from your point of view, these particles will stay for a longer time on the right. (The reason is explained in the figure)&#xD;
&#xD;
![Illustration of how velocity influence timing][8]&#xD;
&#xD;
##&amp;#034;Brighter when Closer&amp;#034;&#xD;
The next question is about the &amp;#034;brighter when closer&amp;#034; rule. We all know that the further a bulb is, the dimmer it would appear to be. This is because the light from the bulb is approximately evenly distributed across solid angles, but as we move further, the solid angle corresponding to our eyes will be smaller. Mathematically, this is saying $I\propto S_0 \frac{d\Omega}{dS}$ where $S_0$ is the surface area of our eyes, $S$ is area, and $\Omega$ is the solid angle.&#xD;
&#xD;
![&amp;#034;Brighter when closer&amp;#034; rule in flat space][9]&#xD;
&#xD;
The same rules apply here in curved spacetime, except the light beams are weirder.&#xD;
&#xD;
![&amp;#034;Brighter when closer&amp;#034; rule in curved space][10]&#xD;
&#xD;
We know that $\frac{d\Omega}{dS}=(\frac{dx}{d\theta_x}\frac{dy}{d\theta_y})^{-1}$. While $\frac{dy}{d\theta_y}=\frac{R_0 \sin \alpha}{\sin \theta_1}$ can be derived using basic solid geometry, $\frac{dx}{d\theta_x}$ must be calculated numerically by tracing the light from the object to the observer. Similarly, we use interpolating function to generalize the result from a set of sample points to the whole space.&#xD;
&#xD;
    (*Reverse ray tracing*)&#xD;
    parfuncrev = &#xD;
      ParametricNDSolveValue[{{tt&amp;#039;&amp;#039;[\[Tau]], &#xD;
          rr&amp;#039;&amp;#039;[\[Tau]], \[Theta]\[Theta]&amp;#039;&amp;#039;[\[Tau]]} == {(&#xD;
          Derivative[1][rr][\[Tau]] Derivative[1][tt][\[Tau]])/(&#xD;
          rr[\[Tau]] - rr[\[Tau]]^2), (&#xD;
           rr[\[Tau]]^2 Derivative[1][&#xD;
              rr][\[Tau]]^2 - (-1 + rr[\[Tau]])^2 Derivative[1][&#xD;
              tt][\[Tau]]^2)/(&#xD;
           2 (-1 + rr[\[Tau]]) rr[\[Tau]]^3) + (-1 + &#xD;
              rr[\[Tau]]) Derivative[1][\[Theta]\[Theta]][\[Tau]]^2, -((&#xD;
           2 Derivative[1][rr][\[Tau]] Derivative[&#xD;
             1][\[Theta]\[Theta]][\[Tau]])/rr[\[Tau]])}, {tt&amp;#039;[0], &#xD;
          rr&amp;#039;[0], \[Theta]\[Theta]&amp;#039;[0]} == {1/(1 - Rs/R1), &#xD;
          Cos[\[Theta]0], -Sqrt[1/(1 - Rs/R1)]/R1 Sin[\[Theta]0]}, {tt[0],&#xD;
           rr[0], \[Theta]\[Theta][0]} == {0, R1, \[Theta]1}, &#xD;
        WhenEvent[\[Theta]\[Theta][\[Tau]] == 0, &#xD;
         &amp;#034;StopIntegration&amp;#034;]}, {tt[\[Tau]], &#xD;
        rr[\[Tau]], \[Theta]\[Theta][\[Tau]]}, {\[Tau], 0, &#xD;
        100}, {\[Theta]0, R1, \[Theta]1}];&#xD;
    (*data used in interpolation*)&#xD;
    \[CapitalDelta]\[Phi] = 1.*^-5;&#xD;
    intensity = &#xD;
      Catenate@Table[{{R, \[Theta]}, &#xD;
         R0^2 With[{\[Theta] = Abs[\[Theta]]}, &#xD;
           Abs[Sin[EmitAngleFunction[&#xD;
                R, \[Theta]]]/(R0 \&#xD;
    Sin[\[Theta]])]*(\[CapitalDelta]\[Phi]/(Sin[&#xD;
                 ReceiveAngleFunction[R, \[Theta]]]* &#xD;
                Subtract @@ (With[{f = &#xD;
                       parfuncrev[&#xD;
                        EmitAngleFunction[&#xD;
                        R, \[Theta]] + # \[CapitalDelta]\[Phi], &#xD;
                        R, \[Theta]][[2, 0]]}, f@f[[1, 1, -1]]] &amp;amp; /@ {-1, &#xD;
                    1})))]}, {R, 2.45 Rs, 5.55 Rs, &#xD;
         0.02 Rs}, {\[Theta], -3 Degree, 543 Degree, 2 Degree}];&#xD;
    &#xD;
    (*Construct InterpolatingFunction*)&#xD;
    IntensityFunction1 = Interpolation[intensity];&#xD;
&#xD;
![With intensity correction 1][11]&#xD;
&#xD;
The figure will be much more realistic in the aspect of intensity after we added this effect. The inner two rings are much dimmer because light bent dramatically is rare after all.&#xD;
&#xD;
##Doppler Effect and Headlight Effect&#xD;
Now its time for Doppler effect and headlight effect. These two effects are related to the movement of light-emitting objects and observers. Though the names of these effects can be forbidding, these effects are quite common in everyday life. Blueshift refers to the phenomenon that when a car is approaching you, the noise made by the car would be more acute and loud, and redshift means when the car is leaving you, the noise would quieter and be of lower frequency. &#xD;
&#xD;
![Doppler effect][12]&#xD;
&#xD;
The equation for the relativistic Doppler effect is:&#xD;
&#xD;
$$&#xD;
    f&amp;#039;=f\frac{\sqrt{1-\beta^2}}{1-\beta \cos \theta}&#xD;
$$&#xD;
&#xD;
where $\beta=\frac{v}{c}$ and $\theta$ is the angle between the velocity direction of the light-emitting object and the light emitted, as observed by an external observer. In this case, we should further add a coefficient of &#xD;
&#xD;
$$&#xD;
 f&amp;#039;&amp;#039;=f&amp;#039;\sqrt{\frac{1 - R_s/R_1}{1 - R_s/R_0}}&#xD;
$$&#xD;
&#xD;
due to general relativistic effects.&#xD;
&#xD;
Headlight effect means when you are driving a car on rainy days, no matter how the wind blows, the raindrops will always run towards the windshield. But if you stop your vehicle, you can see how the wind influences the dropping direction of rain.  &#xD;
&#xD;
![Headlight effect][13]&#xD;
&#xD;
The equation for angle transformation is:&#xD;
&#xD;
$$&#xD;
    \cos \theta&amp;#039;= \frac{\cos \theta +\beta}{1+\beta \cos \theta}&#xD;
$$&#xD;
&#xD;
and such, the intensity difference introduced by this can be written as:&#xD;
&#xD;
$$&#xD;
    \frac{dP&amp;#039;}{d\Omega}= \frac{dP}{d\Omega}\frac{\sin \theta}{\sin \theta&amp;#039;}\frac{d \theta}{d \theta&amp;#039;}=\frac{dP}{d\Omega}\frac{1 - \beta^2}{(1 -\beta \cos \theta)^2}&#xD;
$$&#xD;
&#xD;
Except for the difference in timing brought by the curved spacetime, these two effects are purely in the special relativity regime. The only thing involved in coding is tedious coordinate transformation. &#xD;
&#xD;
    (*Calculate moving speed*)&#xD;
    Calc\[Beta][{R1_, \[Theta]_, \[Phi]_}, {vr_, v\[Theta]_, v\[Phi]_}] :=&#xD;
      Sqrt[vr^2/(1 - &#xD;
           Rs/R1) + (R1 v\[Theta])^2 + (R1 Sin[\[Theta]] v\[Phi])^2]/&#xD;
      Sqrt[1 - Rs/R1]&#xD;
    (*Calculate inner product between moving direction and light direction*)&#xD;
    CalcCosAngle[{R1_, \[Theta]_, \[Phi]_}, {vr_, v\[Theta]_, v\[Phi]_}] :=&#xD;
      With[{v = {vr/Sqrt[1 - Rs/R1], R1 v\[Theta], &#xD;
         R1 Sin[\[Theta]] v\[Phi]}}, &#xD;
      MapThread[With[{\[Theta]0 = EmitAngleFunction[R1, #1]},&#xD;
         With[{vnormed = MapThread[Normalize@*List, v]}, &#xD;
          MapThread[&#xD;
           Dot, {vnormed, Thread@{Cos[\[Theta]0], #2 Sin[\[Theta]0], 0}}, &#xD;
           1]]] &amp;amp;, {{\[Theta], 2 Pi - \[Theta], 2 Pi + \[Theta]}, {-1, &#xD;
         1, -1}}]]&#xD;
    (*Frequency shift, Doppler effect + GR timing effects*)&#xD;
    FrequencyMult[R1_, \[Beta]_, cos_] := &#xD;
     Sqrt[(1 - Rs/R1)/(1 - Rs/R0)]*Sqrt[1 - \[Beta]^2]/(1 - \[Beta] cos)&#xD;
    (*Intensity shift due to headlight effect only*)&#xD;
    IntensityMult2[\[Beta]_, &#xD;
      cos_] := (Sqrt[1 - \[Beta]^2]/(1 - \[Beta] cos))^2&#xD;
&#xD;
Then we can put all these effects together and see how things works out!&#xD;
&#xD;
    &amp;lt;&amp;lt; PhysicalColor`&#xD;
    &#xD;
    IntensityFunctionScaling::usage = &amp;#034;Scale Intensity.&amp;#034;;&#xD;
    Protect@IntensityFunctionScaling;&#xD;
    &#xD;
    Options[RenderFunc] = {ColorFunction -&amp;gt; TemperatureColor, &#xD;
       ColorFunctionScaling -&amp;gt; (# &amp;amp;), IntensityFunctionScaling -&amp;gt; (# &amp;amp;), &#xD;
       &amp;#034;StaticObserver&amp;#034; -&amp;gt; True};&#xD;
    &#xD;
    RenderFunc[R1_, {\[Theta]1_, t1_, \[Gamma]1_}, {T0_, I0_}, &#xD;
      OptionsPattern[]] :=&#xD;
     Function[t, Through[#[t]]] &amp;amp;@Module[{&#xD;
        (*Velocity of observer*)&#xD;
        vobs = N@Sqrt[(1 - Rs/R0) Rs/(2 R0)],&#xD;
        (*list of \[Phi]1 parameters*)&#xD;
        \[Phi]1l = Range[0., 2 Pi, 1 Degree],&#xD;
        (*Polar coordinates \[Theta] and \[Phi]*)&#xD;
        \[Theta]l0, \[Phi]l0,&#xD;
        (*velocity of object and its norm*)&#xD;
        vrl, v\[Theta]l, v\[Phi]l, vnorml&#xD;
        },&#xD;
       (*Polar coordinate \[Theta]*)&#xD;
       \[Theta]l0 = ArcCos[Sin[\[Phi]1l] Sin[\[Theta]1]];&#xD;
       &#xD;
       (*Original \[Phi]*)&#xD;
       \[Phi]l0 = &#xD;
        ArcTan[Cos[\[Phi]1l], Sin[\[Phi]1l] Cos[\[Theta]1]] + \[Gamma]1;&#xD;
       &#xD;
       (*velocity of object*)&#xD;
       vrl = ConstantArray[0, Length@\[Phi]1l];&#xD;
       v\[Theta]l = -(Cos[\[Phi]1l] Sin[\[Theta]1])/&#xD;
          Sqrt[1 - Sin[\[Theta]1]^2 Sin[\[Phi]1l]^2]*Sqrt[Rs/(2 R1^3)];&#xD;
       v\[Phi]l = &#xD;
        1/(Cos[\[Phi]1l]^2/Cos[\[Theta]1] + &#xD;
            Cos[\[Theta]1] Sin[\[Phi]1l]^2)*Sqrt[Rs/(2 R1^3)];&#xD;
       &#xD;
       (*velocity norm*)&#xD;
       vnorml = &#xD;
        Calc\[Beta][{R1, \[Theta]l0, 0}, {vrl, v\[Theta]l, v\[Phi]l}];&#xD;
       &#xD;
       MapThread[Module[{&#xD;
           (*Observed \[Phi]1 parameter - t*)&#xD;
           \[Phi]1t = #3,&#xD;
           (*actual \[Theta] of object*)&#xD;
           \[Theta]l = #1,&#xD;
           (*angle between velocy and ray*)&#xD;
           cosl = #4,&#xD;
           (*Observed values - \[Phi]1*)&#xD;
           (*Geometry*)&#xD;
           \[Theta]obsl, \[Phi]obsl = \[Phi]l0 + #2,&#xD;
           (*Frequency and intensity shift*)&#xD;
           freqobsl, intobsl,&#xD;
           (*helper function*)&#xD;
           helpf&#xD;
           },&#xD;
          \[Theta]obsl = ReceiveAngleFunction[R1, \[Theta]l];&#xD;
          &#xD;
          (*Frequency*)&#xD;
          freqobsl = FrequencyMult[R1, vnorml, cosl];&#xD;
          &#xD;
          (*Process with the non-static observer*)&#xD;
          If[OptionValue[&amp;#034;StaticObserver&amp;#034;] =!= True,&#xD;
           Module[{\[Theta]transl, \[Phi]transl, \[Delta] = ArcSin[vobs]},&#xD;
            (*Geometrics, static frame*)&#xD;
            \[Theta]transl = ArcCos[Sin[\[Theta]obsl] Cos[\[Phi]obsl]];&#xD;
            \[Phi]transl = &#xD;
             ArcTan[Sin[\[Theta]obsl] Sin[\[Phi]obsl], Cos[\[Theta]obsl]];&#xD;
            (*Frequency shift due to movement of observer, &#xD;
            intensity shift is calculated together later*)&#xD;
            freqobsl *= (1 + vobs Cos[\[Theta]transl])/Sqrt[1 - vobs^2];&#xD;
            (*Angle shift due to movement of observer*)&#xD;
            \[Theta]transl = &#xD;
             ArcCos[(vobs + Cos[\[Theta]transl])/(1 + &#xD;
                 vobs Cos[\[Theta]transl])];&#xD;
            (*Transform back*)&#xD;
            (*Here we change the center of viewing angle so that the \&#xD;
    black hole&amp;#039;s center is at {0,0}*)&#xD;
            \[Theta]obsl = &#xD;
             ArcCos[Sin[\[Delta]] Cos[\[Theta]transl] + &#xD;
               Cos[\[Delta]] Sin[\[Theta]transl] Sin[\[Phi]transl]];&#xD;
            \[Phi]obsl = &#xD;
             ArcTan[Cos[\[Delta]] Cos[\[Theta]transl] - &#xD;
               Sin[\[Delta]] Sin[\[Theta]transl] Sin[\[Phi]transl], &#xD;
              Sin[\[Theta]transl] Cos[\[Phi]transl]]&#xD;
            ]&#xD;
           ];&#xD;
          &#xD;
          \[Phi]obsl = &#xD;
           Catenate[&#xD;
            MapIndexed[#1 + 2 Pi #2[[1]] &amp;amp;, Split[\[Phi]obsl, Less]]];&#xD;
          &#xD;
          (*Intensity*)&#xD;
          intobsl = &#xD;
           freqobsl^2*IntensityFunction1[R1, \[Theta]l]*&#xD;
            IntensityMult2[vnorml, cosl]*&#xD;
            TemperatureIntensity[freqobsl T0]/TemperatureIntensity[T0]/&#xD;
             freqobsl^4;&#xD;
          &#xD;
          (*Helper function to construct interpolating functions*)&#xD;
          helpf[l_] := Interpolation[Thread[{\[Phi]1l, l}]];&#xD;
          &#xD;
          With[{&#xD;
            cf = OptionValue[ColorFunction],&#xD;
            (*Interpolating functions*)&#xD;
            t11 = t1,&#xD;
            \[Phi]1f = #3,&#xD;
            \[Theta]func = helpf[\[Theta]obsl],&#xD;
            \[Phi]func = helpf[\[Phi]obsl],&#xD;
            freqfunc = &#xD;
             helpf[OptionValue[ColorFunctionScaling][T0 freqobsl]],&#xD;
            intfunc = &#xD;
             helpf[OptionValue[IntensityFunctionScaling][I0 intobsl]]&#xD;
            },&#xD;
            &#xD;
           (*Final function*)&#xD;
           Function[t,&#xD;
            With[{\[Phi]11 = \[Phi]1f[t + t11]},&#xD;
             {Append[cf[freqfunc[\[Phi]11]], intfunc[\[Phi]11]],&#xD;
              &#xD;
              With[{\[Theta] = \[Theta]func[\[Phi]11], \[Phi] = \&#xD;
    \[Phi]func[\[Phi]11]},&#xD;
               (*Point[{Sin[\[Theta]]Cos[\[Phi]],Sin[\[Theta]]Sin[\[Phi]],&#xD;
               Cos[\[Theta]]}]*)&#xD;
               Point[Tan[\[Theta]] {Cos[\[Phi]], Sin[\[Phi]]}]]}&#xD;
             ]]&#xD;
           ]&#xD;
          ] &amp;amp;, {{\[Theta]l0, 2 Pi - \[Theta]l0, 2 Pi + \[Theta]l0}, {0, &#xD;
          Pi, 0}, GenerateAngleFunctions[R1, \[Theta]1], &#xD;
         CalcCosAngle[{R1, \[Theta]l0, 0}, {vrl, v\[Theta]l, v\[Phi]l}]}]]&#xD;
    (*My version of rasterize, which increase color precision in dimmer areas*)&#xD;
    HDRRasterize[gr_Graphics, convertfunc_, &#xD;
      opts : OptionsPattern[Rasterize]] :=&#xD;
     Module[{rasterl = &#xD;
        Join[ColorSeparate[ColorConvert[Rasterize[gr, opts], &amp;#034;HSB&amp;#034;]], &#xD;
         ColorSeparate[&#xD;
          ColorConvert[&#xD;
           Rasterize[&#xD;
            gr /. RGBColor[r_, g_, b_, op_] :&amp;gt; RGBColor[r, g, b, 16 op], &#xD;
            opts], &amp;#034;HSB&amp;#034;]]], mask, invmask},&#xD;
      mask = Binarize[rasterl[[3]], 1/16];&#xD;
      invmask = 1 - mask;&#xD;
      ColorCombine[{&#xD;
        mask*rasterl[[1]] + invmask*rasterl[[4]],&#xD;
        mask*rasterl[[2]] + invmask*rasterl[[5]],&#xD;
        mask*convertfunc[rasterl[[3]]] + &#xD;
         invmask*convertfunc[rasterl[[6]]/16.]}, &amp;#034;HSB&amp;#034;]&#xD;
      ]&#xD;
    (*Preliminary computation*)&#xD;
    npts = 5000;&#xD;
    rflist = MapThread[&#xD;
       Function[{R1, \[Theta]1, t1, \[Gamma]1, T0, I0}, &#xD;
        RenderFunc[R1, {\[Theta]1, t1, \[Gamma]1}, {T0, I0}, &#xD;
         &amp;#034;StaticObserver&amp;#034; -&amp;gt; False(*,&#xD;
         IntensityFunctionScaling\[Rule](.7(#/.5)^0.5&amp;amp;)*)]],&#xD;
       {RandomReal[{3, 4.5}, npts],&#xD;
        RandomReal[-{83, 86} Degree, npts],&#xD;
        RandomReal[{0, 10000}, npts],&#xD;
        RandomReal[15 Degree + {-2, 2} Degree, npts],&#xD;
        RandomReal[{4000, 10000}, npts],&#xD;
        RandomReal[{.03, .1}, npts]&#xD;
        }&#xD;
       ];&#xD;
    (*rendering!!!*)&#xD;
    g = Graphics[{(*AbsolutePointSize@.1,White,Point[{Sin[20Degree]Cos[#],&#xD;
        Sin[20Degree]Sin[#],Cos[20Degree]}&amp;amp;/@Range[0.,360.Degree,&#xD;
        60.Degree]],*)AbsoluteThickness@2, &#xD;
        Map[Line[#[[;; , 2, 1]], &#xD;
           VertexColors -&amp;gt; &#xD;
            MapThread[&#xD;
             Function[{col, len, mult}, &#xD;
              MapAt[mult^2*#*0.006/len &amp;amp;, col, 4]], {#[[;; , 1]], &#xD;
              Prepend[#, #[[1]]] &amp;amp;@&#xD;
               BlockMap[Norm[#[[2]] - #[[1]]] &amp;amp;, #[[;; , 2, 1]], 2, 1], &#xD;
              Subdivide[Length[#] - 1]}]] &amp;amp;, &#xD;
         Reverse@Transpose[&#xD;
           Through[rflist[#]] &amp;amp; /@ (Range[0, 3, .1]), {3, 2, 1}], {2}]}, &#xD;
       Background -&amp;gt; Black, ImageSize -&amp;gt; {500, Automatic}, &#xD;
       PlotRange -&amp;gt; {{-1.28, 1.28}, {-0.72, 0.72}}];&#xD;
&#xD;
    HDRRasterize[g, #^(1/2.2) &amp;amp;, ImageSize -&amp;gt; {1920, 1080}]&#xD;
&#xD;
![With all effects, static observer][14]&#xD;
&#xD;
Well, because objects at left are moving towards you, they will appear much brighter and blue-ish, while objects at right are much dimmer and red-ish.&#xD;
&#xD;
We can also consider the movement of the observer, which will make the image something like this:&#xD;
&#xD;
![With all effects, observer moving][15]&#xD;
&#xD;
Hooray!&#xD;
&#xD;
The notebook can be found in the attachment or at [my github repo](https://github.com/wjxway/Realistic_Blackhole_Accretion_Disk).&#xD;
&#xD;
&#xD;
  [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=bh10.png&amp;amp;userId=1340903&#xD;
  [2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=T_001.png&amp;amp;userId=1340903&#xD;
  [3]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Path_4.png&amp;amp;userId=1340903&#xD;
  [4]: https://community.wolfram.com//c/portal/getImageAttachment?filename=illus2.png&amp;amp;userId=1340903&#xD;
  [5]: https://community.wolfram.com//c/portal/getImageAttachment?filename=illus1.png&amp;amp;userId=1340903&#xD;
  [6]: https://community.wolfram.com//c/portal/getImageAttachment?filename=LightBending.png&amp;amp;userId=1340903&#xD;
  [7]: https://community.wolfram.com//c/portal/getImageAttachment?filename=WithTimeCorrection.png&amp;amp;userId=1340903&#xD;
  [8]: https://community.wolfram.com//c/portal/getImageAttachment?filename=illus3.png&amp;amp;userId=1340903&#xD;
  [9]: https://community.wolfram.com//c/portal/getImageAttachment?filename=IntensityIllus.png&amp;amp;userId=1340903&#xD;
  [10]: https://community.wolfram.com//c/portal/getImageAttachment?filename=illus4.png&amp;amp;userId=1340903&#xD;
  [11]: https://community.wolfram.com//c/portal/getImageAttachment?filename=WithIntensity1.png&amp;amp;userId=1340903&#xD;
  [12]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Doppler.jpg&amp;amp;userId=1340903&#xD;
  [13]: https://community.wolfram.com//c/portal/getImageAttachment?filename=FrontLight.jpg&amp;amp;userId=1340903&#xD;
  [14]: https://community.wolfram.com//c/portal/getImageAttachment?filename=WithAllEffects.png&amp;amp;userId=1340903&#xD;
  [15]: https://community.wolfram.com//c/portal/getImageAttachment?filename=WithObserverMoving.png&amp;amp;userId=1340903</description>
    <dc:creator>Jingxian Wang</dc:creator>
    <dc:date>2020-07-02T11:26:03Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/441498">
    <title>How do I repeat/loop multiple functions that are related?</title>
    <link>https://community.wolfram.com/groups/-/m/t/441498</link>
    <description>Hello guys, I&amp;#039;m stuck with this question for some time.&#xD;
For my equation, I need to use WolframAlpha for my data.&#xD;
Firstly, I fix my initial water temperature as 500 Kelvin. Eg:&#xD;
&#xD;
    Twater = 300&#xD;
    Cwater = QuantityMagnitude[&#xD;
      ThermodynamicData[&amp;#034;Water&amp;#034;, &#xD;
       &amp;#034;ThermalConductivity&amp;#034;, {&amp;#034;Temperature&amp;#034; -&amp;gt; &#xD;
         Quantity[Twater, &amp;#034;Kelvins&amp;#034;]}]]&#xD;
&#xD;
With Cwater determined,&#xD;
I can implement the next 2 functions&#xD;
&#xD;
    Dwater = (5 Cwater)/\[Pi]&#xD;
    Ewater = Dwater^3 + 2 Cwater&#xD;
&#xD;
Then by using ParametricNDSolveValue, I can determine the value of Z&#xD;
&#xD;
    ClassicalRungeKuttaCoefficients[4, prec_] := &#xD;
      With[{amat = {{1/2}, {0, 1/2}, {0, 0, 1}}, &#xD;
        bvec = {1/6, 1/3, 1/3, 1/6}, cvec = {1/2, 1/2, 1}}, &#xD;
       N[{amat, bvec, cvec}, prec]];&#xD;
    &#xD;
    f = ParametricNDSolveValue[{Derivative[1][y][x] == &#xD;
         Piecewise[{{(y[x] + x^3 + 3 z - 120*Ewater), 0 &amp;lt;= x &amp;lt;= 1},&#xD;
           {(y[x] + x^2 + 2 z), 1 &amp;lt;= x &amp;lt;= 2},&#xD;
           {(y[x] + x + z), 2 &amp;lt;= x &amp;lt;= 3}}],&#xD;
        y[0] == 0},&#xD;
       y[3.],&#xD;
       {x, 0., 3.},&#xD;
       z,&#xD;
       Method -&amp;gt; {&amp;#034;ExplicitRungeKutta&amp;#034;, &amp;#034;DifferenceOrder&amp;#034; -&amp;gt; 4, &#xD;
         &amp;#034;Coefficients&amp;#034; -&amp;gt; ClassicalRungeKuttaCoefficients}, &#xD;
       StartingStepSize -&amp;gt; 1/10];&#xD;
    &#xD;
    point = {z /. FindRoot[f[z] == 100., {z, 1}, Evaluated -&amp;gt; False], &#xD;
       100.};&#xD;
    &#xD;
    FindRoot[f[z] == 100., {z, 1}, Evaluated -&amp;gt; False]&#xD;
    &#xD;
Lastly, to find the new temperature of water&#xD;
&#xD;
    Tnew = 170 + 1.89*z /. &#xD;
      FindRoot[f[z] == 100., {z, 1}, Evaluated -&amp;gt; False]&#xD;
    &#xD;
I wanted to repeat Twater with Tnew until Twater=Tnew-&amp;gt;True and the loop stop.&#xD;
I need to start Twater with a value, (only to replace Twater=Tnew after the first equation and keep press shift+enter repeatedly)&#xD;
&#xD;
I&amp;#039;ve tried some Do Loop or For Loop and even FixedPoint but still don&amp;#039;t know how to combine multiple functions/equations into 1 loop....&#xD;
I apologize because I&amp;#039;ve been asking this question a few times, or maybe some of you have answered me in some way, but I still did not understand how to do this.&#xD;
Thank you very much for your time.</description>
    <dc:creator>Thai Kee Gan</dc:creator>
    <dc:date>2015-02-13T05:57:04Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/273260">
    <title>Derivative of a list of data values</title>
    <link>https://community.wolfram.com/groups/-/m/t/273260</link>
    <description>Dear All,

I want to ask your advise. I have a variable q as a function of time but I already have the values of q for each time step.
So do you know any command in Mathematica for getting the derivative values of q?
There are some commands such as:
dq/dt = D[q[t],t] or dq/dt = q&amp;#039;[t] but I think I can use that command if I have q as an equation but I have q as values.

So I used the below method to calculate the derivative:

    dqdt = Table[(q[t + 1] - q[t - 1])/2, {t, 1, 99}]

Please refer to attach. titled &amp;#034;Derivative.nb&amp;#034; for the script.
So may I know if the above method is correct? And may I know the alternative ways for calculating derivative like in this case?
Thanks a lot for your kind attention.

Best Regards,
Intan</description>
    <dc:creator>INTAN SUPRABA</dc:creator>
    <dc:date>2014-06-10T01:43:43Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1132423">
    <title>Extending FindRoot</title>
    <link>https://community.wolfram.com/groups/-/m/t/1132423</link>
    <description>The function `FindRoot` can only find one root; there is no way of finding multiple roots. User J. M. extended the FindRoot by the function [FindAllCrossings][1] by changing Stan Wagon&amp;#039;s book Mathematica in Action slightly.&#xD;
&#xD;
The implementation is pretty slick. You plot the function on a certain range and tell the `Plot` function to mesh the zeros, then you extract the zeros and use `FindRoot` with them as an initial condition.&#xD;
&#xD;
But this implementation has a major drawback; it fails in cases where the function doesn&amp;#039;t cross zero, as `x^2` for example.&#xD;
&#xD;
To extend J. M. implementation I added some more lines of code, and I&amp;#039;ve made the code more verbose. The new lines of code calculate the zeros of the derivative of the function and then test it is close to zero and later refine it with `FindRoot`, this works even with functions as `Abs[x]`, which has discontinuous derivative and never crosses zero, but thanks to the interpolated result, it takes care of that.&#xD;
&#xD;
    Options@FindRoots = Sort@Join[Options@FindRoot, {MaxRecursion -&amp;gt; Automatic, PerformanceGoal :&amp;gt; $PerformanceGoal, PlotPoints -&amp;gt; Automatic, Debug -&amp;gt; False, ZeroTolerance -&amp;gt; 10^-2}];&#xD;
    &#xD;
    FindRoots[fun_, {var_, min_, max_}, opts:OptionsPattern[]] := Module[{PlotRules, RootRules, g, g2, pts, pts2, lpts, F, sol},&#xD;
    	(* Extract the Options *)&#xD;
    	PlotRules = Sequence @@ FilterRules[Join[{opts}, Options@FindRoots], Options@Plot];&#xD;
    	RootRules = Sequence @@ FilterRules[Join[{opts}, Options@FindRoots], Options@FindRoot];&#xD;
    &#xD;
    	(* Plot the function and &amp;#034;mesh&amp;#034; the point with y-coordinate 0 *)&#xD;
    	g = Normal@Plot[fun, {var, min, max}, MeshFunctions -&amp;gt; (#2 &amp;amp;), Mesh -&amp;gt; {{0}}, Method -&amp;gt; Automatic, Evaluate@PlotRules];&#xD;
    &#xD;
    	(* Get the meshes zeros *)&#xD;
    	pts = Cases[g, Point[p_] :&amp;gt; SetPrecision[p[[1]], OptionValue@WorkingPrecision], Infinity];&#xD;
    	(* Get all plot points *)&#xD;
    	lpts = Join@@Cases[g, Line[p_] :&amp;gt; SetPrecision[p, OptionValue@WorkingPrecision], Infinity];&#xD;
    &#xD;
    	(* Derive the interpolated data to find other zeros *)&#xD;
    	F = Interpolation[lpts, InterpolationOrder-&amp;gt;2];&#xD;
    	g2 = Normal@Plot[Evaluate@D[F@var, var], {var, min, max}, MeshFunctions -&amp;gt; (#2 &amp;amp;), Mesh -&amp;gt; {{0}}, Method -&amp;gt; Automatic, Evaluate@PlotRules];&#xD;
    &#xD;
    	(* Get the meshes zeros and retain only small ones *)&#xD;
    	pts2 = Cases[g2, Point[p_] :&amp;gt; SetPrecision[p[[1]], OptionValue@WorkingPrecision], Infinity];&#xD;
    	pts2 = Select[pts2, Abs[F@#] &amp;lt; OptionValue@ZeroTolerance &amp;amp;];&#xD;
    	pts = Join[pts, pts2]; (* Join all zeros *)&#xD;
    &#xD;
    	(* Refine zeros by passing each point through FindRoot *)&#xD;
    	If[Length@pts &amp;gt; 0,&#xD;
    		pts = Map[FindRoot[fun, {var, #}, Evaluate@RootRules]&amp;amp;, pts];&#xD;
    		sol = Union@Select[pts, min &amp;lt;= Last@Last@# &amp;lt;= max &amp;amp;];&#xD;
    		(* For debug purposes *)&#xD;
    		If[OptionValue@Debug, Print@Show[g, Graphics@{PointSize@0.02, Red, Point[{var, fun} /. sol]}]];&#xD;
    		sol&#xD;
    	,&#xD;
    		If[OptionValue@Debug, Print@g];&#xD;
    		{}&#xD;
    	]&#xD;
    ]&#xD;
&#xD;
Example:&#xD;
&#xD;
![enter image description here][2]&#xD;
&#xD;
My primary use of this function is to find the eigenvalues of dielectric waveguides. They are found as the zeros of the boundary conditions.&#xD;
&#xD;
&#xD;
  [1]: https://mathematica.stackexchange.com/questions/5663/about-multi-root-search-in-mathematica-for-transcendental-equations#answer-5666&#xD;
  [2]: http://community.wolfram.com//c/portal/getImageAttachment?filename=2017-07-01_153306.png&amp;amp;userId=845022</description>
    <dc:creator>Thales Fernandes</dc:creator>
    <dc:date>2017-07-01T18:39:46Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1670775">
    <title>Counting Trailing Zeros Of Factorials</title>
    <link>https://community.wolfram.com/groups/-/m/t/1670775</link>
    <description>##Introduction##&#xD;
You may have noticed that the factorial function for integers generates a lot of trailing zeros at the end e.g. 100! evaluates to&#xD;
&#xD;
    9332621544394415268169923885626670049071596826438162146859296389521759\&#xD;
    9993229915608941463976156518286253697920827223758251185210916864000000\&#xD;
    000000000000000000&#xD;
&#xD;
That&amp;#039;s 24 zeros right there. Maybe you would like to figure out how to calculate the exact number for arbitrary input integers? And then maybe for any chosen radix as well i.e. not using the decimal representation? I don&amp;#039;t want to spoil the fun for you, so please go chew away at this nice little mathematical diversion. The asymptotic &amp;#034;TZF&amp;#034; function for large integers is really compute-friendly, so for &amp;#034;easy&amp;#034; large integers you will be able to do the algebra just using a simple rule.&#xD;
&#xD;
Well and then it is always possible I have made a mistake, so I include my notebook on this problem for you to compare.&#xD;
&#xD;
Have fun!&#xD;
&#xD;
![enter image description here][1]&#xD;
&#xD;
In the seventies when I got my first TI pocket calculator in school I developed a certain fascination for the factorial function. It was basically the most dangerous function around because if you entered any integer larger than 69 it would blow up with an error because it could not calculate numbers with more than two digits in the base-10 exponent and for most of them it could of course only show the first few most significant digits. &#xD;
&#xD;
So it took me almost 40 years and the mind-boggling capacity of WL to handle arbitrary-sized integers (well almost) to ask the following question: What is the number of trailing zeros in $n$ factorial? As a short reminder n! is the mathematical notation for the product of all positive integers less or equal to n.&#xD;
&#xD;
As you can easily see from an example there are plenty of trailing zeros in the factorial of reasonably-sized integers: &#xD;
&#xD;
    100!&#xD;
&#xD;
&amp;gt; `9332621544394415268169923885626670049071596826438162146859296389521759\&#xD;
9993229915608941463976156518286253697920827223758251185210916864000000\&#xD;
000000000000000000`&#xD;
&#xD;
Well to answer the question above we reformulate it as the number of sought zeros is equal to how many times n factorial can be divided (meaning integer division) by ten without getting a remainder. But for getting a factor of 10 there needs to be a corresponding factor of 5 and one factor of 2 in the prime factorization of $n$ factorial. Since every other number contains at least a factor of 2 in its prime factorization we can safely count only the factors of 5 in the factorization of the first n integers so we get a first (very functional and &amp;#034;pattern matchy&amp;#034; way to calculate the trailing zero function TZF:&#xD;
&#xD;
    TZF1[n_] := &#xD;
     Flatten[FactorInteger[Range[n]] , 1] // Cases[{5, a_} -&amp;gt; a] // Total&#xD;
&#xD;
    ListPlot[Table[TZF1[n], {n, 100}], Joined -&amp;gt; True, ImageSize -&amp;gt; Large,&#xD;
      PlotRange -&amp;gt; All]&#xD;
&#xD;
![enter image description here][2]&#xD;
&#xD;
Well it looks pretty step-like with regular intervals so let&amp;#039;s plot the differences:&#xD;
&#xD;
    ListPlot[Differences[Table[TZF1[n], {n, 100}]], Joined -&amp;gt; True, &#xD;
     ImageSize -&amp;gt; Large, PlotRange -&amp;gt; All]&#xD;
&#xD;
![enter image description here][3]&#xD;
&#xD;
Aha! For each $5^i$ we get i new trailing zeros, but that is then equal to just summing the integer quotients of dividing n by increasing powers of $5^i$. So we have another candidate for the trailing zeros which definitely looks much more procedural:&#xD;
&#xD;
    TZF2[n_] := Module[{i = 1, result = 0},  While[5^i &amp;lt;= n, result += Quotient[n, 5^i]; i++]; result]&#xD;
&#xD;
And finally we might always have done a mistake so let&amp;#039;s just see how long the last group of digits is for any n larger than 4, which is the brute force way to get the answer:&#xD;
&#xD;
    TZF3[n_] :=  If[n &amp;lt; 5, 0,  IntegerDigits[Factorial[n]] // SplitBy[#, 1] &amp;amp; // Part[#, -1] &amp;amp; //  Length]&#xD;
&#xD;
    m = 150; ListPlot[{Table[TZF1[n], {n, m}], Table[TZF2[n], {n, m}], &#xD;
      Table[TZF3[n], {n, m}]}, Joined -&amp;gt; True, ImageSize -&amp;gt; Large,  PlotRange -&amp;gt; All]&#xD;
&#xD;
![enter image description here][4]&#xD;
&#xD;
All well it seems, of course not everything worked out right at first trial, but now that all three seem to coincide, it seems pretty watertight right?&#xD;
So then let&amp;#039;s see which form might be most efficient to calculate the TZF function:&#xD;
&#xD;
    n = 10000;&#xD;
    Timing[TZF1[n]]&#xD;
    Timing[TZF2[n]]&#xD;
    Timing[TZF3[n]]&#xD;
&#xD;
    {0.041059, 2499} &#xD;
    {0.000055, 2499}&#xD;
    {0.043205, 2499}&#xD;
&#xD;
So you see functional is not always faster unfortunately, but it is also surprising to see that taking the long detour to calculate the whole factorial does equally well roughly as the first variant which only factorizes rather small numbers.&#xD;
&#xD;
But back to the original question we can see that we answer the original question pretty accurately by calculating the TZF function divided by n as a geometric sum:&#xD;
&#xD;
    n =.;&#xD;
    Sum[1/5^i, {i, 1, \[Infinity]}]&#xD;
&#xD;
&amp;gt; 1/4&#xD;
&#xD;
So the trailing number of zeros of n factorial is approximately $n/4$ for large n (to be more accurate take one less). So if you get the question at the next party &amp;#034;how many trailing zeros are there in 10000 factorial?&amp;#034; just say &amp;#034;2499 of course&amp;#034;!&#xD;
&#xD;
So what about other radices (plural for radix or base of the integer digit representation)? To find an the answer we have to consider the prime factorization of the radix which then of course can have more (or less) than two prime factors and each with a separate multiplicity to form the radix as a product. So for each of these prime factors of the radix  $p^k$ we then have to calculate how many times p appears in the positive integer numbers smaller or equal to n and find the integer quotient when dividing by k. The smallest of these is then our trailing zeros count.&#xD;
&#xD;
    TZF4[n_, r_] := Quotient[Total[ Cases[Flatten[FactorInteger[Range[n]] , 1] , {#[[1]], a_} -&amp;gt; &#xD;
            a]], #[[2]]] &amp;amp; /@ FactorInteger[r] // Min&#xD;
&#xD;
    TZF5[n_, r_] := &#xD;
     Module[{f = FactorInteger[r], q = Table[0, Length[FactorInteger[r]]],&#xD;
        i, p, q0},&#xD;
      Do[i = 1; p = f[[j, 1]]; q0 = 0;&#xD;
       While[p^i &amp;lt;= n, q0 += Quotient[n, p^i]; i++];&#xD;
       q[[j]] = q0&#xD;
       , {j, Length[f]}];&#xD;
      If[Min[q] &amp;gt; 0, Min[Quotient[q, f[[;; , 2]]]], 0]&#xD;
      ]&#xD;
&#xD;
    TZF6[n_, r_] := &#xD;
     IntegerDigits[Factorial[n], r] // SplitBy[#, 1] &amp;amp; // &#xD;
      If[Part[#, -1][[1]] == 0, Length[Part[#, -1]], 0] &amp;amp;&#xD;
&#xD;
Let&amp;#039;s see if these agree to iron out obvious mistakes by feeding random samples. But beware, the factorial is still dangerous and will exhaust your physical memory if you throw in too big numbers or too small radices.&#xD;
&#xD;
    Table[{n = RandomInteger[10000], r = RandomInteger[{5, 30}], &#xD;
       TZF4[n, r], TZF5[n, r], TZF6[n, r]}, 10] // TableForm&#xD;
&#xD;
![enter image description here][5]&#xD;
&#xD;
    Table[{n = RandomInteger[10000], TZF1[n], TZF2[n], TZF3[n], &#xD;
       TZF4[n, 10], TZF5[n, 10], TZF6[n, 10]}, 10] // TableForm&#xD;
&#xD;
![enter image description here][6]&#xD;
&#xD;
In order to get asymptotic values of the trailing zeros you now need to divide n by $(p-1) k$. You have to do this only with the prime factor that results in the largest value of $(p-1) k$ of course. Then you round down again and you will be mostly very accurate. So let&amp;#039;s do an example:&#xD;
&#xD;
    TZF5[10000, 72]&#xD;
&#xD;
&amp;gt; 2498&#xD;
&#xD;
For radix 72 the prime decomposition is $2^3 3^2$, so again it&amp;#039;s a division by four (from the first factor) but now we&amp;#039;d actually would have to subtract 2 to get the right number. If you end up with a tricky radix decomposition for the party trick you might actually have to consult the pocket calculator on your smartphone for the division. To close out I have to confess that I still own a working HP-15C, an icon of computation devices and a testament to solid engineering:&#xD;
&#xD;
Well I am looking forward to the day when we are going to have hardware that durable again and being able to run WL from it.&#xD;
&#xD;
If you liked this piece and want to explore further, why not generalizing the TZF functions above to mixed radix representations or make your own variant of them to optimize code, memory or performance.&#xD;
&#xD;
![enter image description here][7]&#xD;
&#xD;
&#xD;
  [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=42551.png&amp;amp;userId=20103&#xD;
  [2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=65422.png&amp;amp;userId=20103&#xD;
  [3]: https://community.wolfram.com//c/portal/getImageAttachment?filename=64973.png&amp;amp;userId=20103&#xD;
  [4]: https://community.wolfram.com//c/portal/getImageAttachment?filename=78994.png&amp;amp;userId=20103&#xD;
  [5]: https://community.wolfram.com//c/portal/getImageAttachment?filename=54855.png&amp;amp;userId=20103&#xD;
  [6]: https://community.wolfram.com//c/portal/getImageAttachment?filename=44026.png&amp;amp;userId=20103&#xD;
  [7]: https://community.wolfram.com//c/portal/getImageAttachment?filename=44607.png&amp;amp;userId=20103</description>
    <dc:creator>Fabian Wenger</dc:creator>
    <dc:date>2019-04-27T18:17:05Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/610335">
    <title>Solving 2D Incompressible Flows using Finite Elements</title>
    <link>https://community.wolfram.com/groups/-/m/t/610335</link>
    <description>Introduction&#xD;
------------&#xD;
&#xD;
I was inspired by the Wolfram blog by [Mokashi][1] showing how to use *Mathematica* to solve a 2D stationary Navier-Stokes flow using a finite difference scheme to write this blog. I thought it should be possible to solve the 2D cavity box flow problem using *Mathematica&amp;#039;s* Finite Element capabilities. In the following I show how the problem can be discretized and solved by the Finite Element method using an iterative scheme.&#xD;
&#xD;
Solving the 2D cavity flow using FE&#xD;
-----------------------------------&#xD;
In order to solve the cavity flow problem using the finite element method, we first need to define the geometry of the box containing the fluid (the region) we want to discretize.&#xD;
The region is a rectangular box with width *a* and height *b*:&#xD;
&#xD;
    \[CapitalOmega] = Rectangle[{0, 0}, {a, b}] /. {a -&amp;gt; 1, b -&amp;gt; 1};&#xD;
    RegionPlot[\[CapitalOmega], AspectRatio -&amp;gt; Automatic]&#xD;
![The region][2]&#xD;
&#xD;
&#xD;
----------&#xD;
&#xD;
&#xD;
In order to use the FE capabilities in *Mathematica*, we first have to load the FE package:&#xD;
&#xD;
    Needs[&amp;#034;NDSolve`FEM`&amp;#034;]&#xD;
The mesh is created using the `ToElementMesh` command. In our case, we only input the region to be meshed and the maximum element size. The maximum element size is specified as 1/1000 of the characteristic length. The mesh will be used to discretize the PDEs.&#xD;
&#xD;
    mesh = ToElementMesh[\[CapitalOmega], &amp;#034;MaxCellMeasure&amp;#034; -&amp;gt; 1/1000, &#xD;
      &amp;#034;MeshElementType&amp;#034; -&amp;gt; QuadElement]&#xD;
&#xD;
`ToElementMesh` returns a mesh object showing the bounds of the discretized region, the element type and the number of elements. The actual mesh can be displayed in wireframe using the `Wireframe` option:&#xD;
&#xD;
    mesh[&amp;#034;Wireframe&amp;#034;]&#xD;
&#xD;
![The mesh][3]&#xD;
&#xD;
&#xD;
----------&#xD;
&#xD;
The operator form of the 2D stationary Navier-Stokes flow&#xD;
---------------------------------------------------------&#xD;
Now that we have defined the region and the mesh, we will need to input the PDEs describing our problem. Refer to the post by  [Mokashi][4] to see the form of the equations.&#xD;
The unknowns are described by the velocity vector ***u*** and the scalar pressure field *p*&#xD;
&#xD;
    uv = {u[x, y], v[x, y]}; pxy = p[x, y];&#xD;
&#xD;
The stress tensor is defined by:&#xD;
&#xD;
    \[Sigma] = -pxy IdentityMatrix[2] + 2/re Outer[ D, uv, {x, y}]*1/2&#xD;
&#xD;
where `re` is the Reynolds number.&#xD;
The stationary N-S equations are defined by:&#xD;
&#xD;
    NS = \!\(&#xD;
    \*SubscriptBox[\(\[Del]\), \({x, y}\)]uv\). uv - \!\(&#xD;
    \*SubscriptBox[\(\[Del]\), \({x, y}\)] . \[Sigma]\);&#xD;
    MatrixForm[NS]&#xD;
&#xD;
 - ![The Navier-Stokes equations][5]&#xD;
&#xD;
Adding the continuity condition gives the complete operator for the 2D N-S equations:&#xD;
&#xD;
    NSOperator = {NS, \!\(&#xD;
    \*SubscriptBox[\(\[Del]\), \({x, y}\)] . uv\)} // Flatten&#xD;
&#xD;
 - ![Complete Navier-Stokes equations][6]&#xD;
&#xD;
&#xD;
&#xD;
&#xD;
----------&#xD;
&#xD;
It is only possible to solve a linear set of PDEs using the FE method. The operator form of the N-S equations derived above are nonlinear due to the convective terms which are products of the solution and it&amp;#039;s derivatives.&#xD;
However, it is possible to linearise these terms and use an iterative scheme to calculate the nonlinear terms.Through a Newton linearization it is possible to show that:&#xD;
&#xD;
 - ![enter image description here][7]&#xD;
&#xD;
Now, we only need to specify a reasonable starting value of u0 in order to calculate an approximation to the nonlinear term.We can now perform the next iteration by simply assigning the velocity field obtained from the last solution as an estimate to the next solution. However, we will need a criterion to terminate the iterations. A typical termination criterion would be when the flow field does not change much from one iteration to the next. This can be expressed as ![Termination criterion][8] where ![\[Epsilon\]][9] is a given tolerance and ![k&amp;#039;th veleocity field norm][10] is the Norm of the velocity vector and ![Initial velocity field norm][11] is the norm of the initial velocity field from the solution of the Stokes flow.&#xD;
&#xD;
&#xD;
Boundary conditions&#xD;
-------------------&#xD;
&#xD;
The boundary conditions for the 2D cavity flow in a box are given by:&#xD;
&#xD;
    bcs = {&#xD;
       DirichletCondition[{u[x, y] == 1, v[x, y] == 0.}, y == 1],&#xD;
       DirichletCondition[{u[x, y] == 0., v[x, y] == 0.}, x == 1], &#xD;
       DirichletCondition[{u[x, y] == 0., v[x, y] == 0.}, y == 0], &#xD;
       DirichletCondition[{u[x, y] == 0., v[x, y] == 0.}, x == 0], &#xD;
       DirichletCondition[p[x, y] == 0., y == 1 &amp;amp;&amp;amp; x == 1]};&#xD;
We have prescribed no-slip conditions (*u*=0, *v*=0) at the left, right and lower side of the box. At the lid the  *u* velocity is given by a characteristic velocity *U* = 1 while the *v* velocity is set to zero at this boundary. Since we now have specified the velocity on the complete boundary (all sides), the velocities are unique while the pressure is fixed up to one additive constant. Hence, we only need to define one additional boundary condition for the pressure. In our case we have set the pressure *p*=0 at the upper left corner of the box. &#xD;
&#xD;
Solving the cavity flow problem for Re=100&#xD;
-----------------------------------&#xD;
Wrapping everything together, we will solve the 2D cavity flow for Reynold&amp;#039;s number 100 in an iterative scheme.&#xD;
We will use the solution of the Stoke&amp;#039;s flow as our initial velocity field. The Stokes flow is simply derived from the N-S operator neglecting the convective terms:&#xD;
&#xD;
    StokesOperator = NSOperator /. {u[x, y] -&amp;gt; 0, v[x, y] -&amp;gt; 0};&#xD;
&#xD;
 - ![List item][12]&#xD;
&#xD;
The PDEs for a Stokes flow with Reynolds number of 100:&#xD;
&#xD;
    pde = StokesOperator == {0, 0, 0} /. re -&amp;gt; 100;&#xD;
A stable solution can be found if the velocities are interpolated with a higher order than the pressure. `NDSolve` allows an interpolation order for each dependent variable to be specified.&#xD;
&#xD;
    {u0, v0, p0} = &#xD;
      NDSolveValue[{pde, bcs}, {u, v, p}, {x, y} \[Element] mesh, &#xD;
       Method -&amp;gt; {&amp;#034;FiniteElement&amp;#034;, &#xD;
         &amp;#034;InterpolationOrder&amp;#034; -&amp;gt; {u -&amp;gt; 2, v -&amp;gt; 2, p -&amp;gt; 1}, &#xD;
         &amp;#034;IntegrationOrder&amp;#034; -&amp;gt; 5}];&#xD;
The velocity field is easily visualized using the `StreamPlot` function:&#xD;
&#xD;
    stokes = StreamPlot[{u0[x, y], v0[x, y]}, {x, 0, 1}, {y, 0, 1}, &#xD;
      StreamPoints -&amp;gt; Fine, StreamColorFunction -&amp;gt; Hue, &#xD;
      StreamColorFunctionScaling -&amp;gt; False, &#xD;
      PlotLabel -&amp;gt; &#xD;
       Style[&amp;#034;Stokes flow for \!\(\*SubscriptBox[\(R\), \(e\)]\)=100&amp;#034;, &#xD;
        Black, FontFamily -&amp;gt; &amp;#034;Times&amp;#034;, Bold]]&#xD;
![Flow field of Stokes solution][13]&#xD;
&#xD;
Preparing for the iterations&#xD;
----------------------------&#xD;
To calculate the norm of the solution, wee need to access the raw solution vectors directly instead of the `InterPolatingFunction` returned by `NDSolveValue` above. We can access the raw solution vectors through the `NDSolve&amp;#039;ProcessEquations`. This will lead to a slightly more complicated work flow, but gives us access to the `StateData` object and it&amp;#039;s data structure:&#xD;
&#xD;
    pde = StokesOperator == {0, 0, 0} /. re -&amp;gt; 100;&#xD;
    {state} = &#xD;
     NDSolve`ProcessEquations[{pde, bcs}, {u, v, p}, {x, y} \[Element] &#xD;
       mesh, Method -&amp;gt; {&amp;#034;FiniteElement&amp;#034;, &#xD;
        &amp;#034;InterpolationOrder&amp;#034; -&amp;gt; {u -&amp;gt; 2, v -&amp;gt; 2, p -&amp;gt; 1}, &#xD;
        &amp;#034;IntegrationOrder&amp;#034; -&amp;gt; 5}]&#xD;
    {NDSolve`StateData[&amp;#034;&amp;lt;&amp;#034; &amp;#034;SteadyState&amp;#034; &amp;#034;&amp;gt;&amp;#034;]}&#xD;
From the `StateData` object we get access to the `FiniteElementData`&#xD;
&#xD;
    state[&amp;#034;FiniteElementData&amp;#034;][&amp;#034;FEMMethodData&amp;#034;][&amp;#034;Properties&amp;#034;]&#xD;
    &#xD;
    {&amp;#034;DegreesOfFreedom&amp;#034;, &amp;#034;ElementMesh&amp;#034;, &amp;#034;IncidentOffsets&amp;#034;, &amp;#034;Incidents&amp;#034;, \&#xD;
    &amp;#034;IntegrationOrder&amp;#034;, &amp;#034;InterpolationOrder&amp;#034;, &amp;#034;Precision&amp;#034;, &amp;#034;Properties&amp;#034;, \&#xD;
    &amp;#034;SolutionData&amp;#034;, &amp;#034;TotalDegreesOfFreedom&amp;#034;, &amp;#034;VariableData&amp;#034;}&#xD;
&#xD;
The `IncidentOffset` dataset gives us the offsets of the dependent variables in the set of the discretised PDEs:&#xD;
&#xD;
    offset = state[&amp;#034;FiniteElementData&amp;#034;][&amp;#034;FEMMethodData&amp;#034;][&amp;#034;IncidentOffsets&amp;#034;]&#xD;
    &#xD;
    {0, 1089, 4290, 7491}&#xD;
The `VariableData` gives us the sequence of the dependent variables:&#xD;
The incidents of the first dependent variable which is the pressure *p* range from the first offset plus one to the second offset:&#xD;
&#xD;
    split = MapThread[#1 -&amp;gt; {#2} &amp;amp;, {vd[[3]], &#xD;
       Span @@@ Transpose[{Most[# + 1], Rest[#]} &amp;amp;[offset]]}]&#xD;
    &#xD;
    {p -&amp;gt; {1 ;; 1089}, u -&amp;gt; {1090 ;; 4290}, v -&amp;gt; {4291 ;; 7491}}&#xD;
Now we have the necessary information to extract the raw solution for the velocity field and compute our norm for each iteration.&#xD;
For a steady state problem, invoking `NDSolve&amp;#039;Iterate` finds the solution of a system of equations with `LinearSolve`:&#xD;
&#xD;
    NDSolve`Iterate[state];&#xD;
The raw solution vector is now available from the `StateData` object:&#xD;
&#xD;
    sol = state[&amp;#034;FiniteElementData&amp;#034;][&amp;#034;Solution&amp;#034;];&#xD;
&#xD;
The raw velocity vector can be extracted dropping the pressure terms from the solution vector:&#xD;
&#xD;
    uv0 = Drop[sol, First[p /. split]];&#xD;
&#xD;
We store the vector for using it to compute the norm in the next iteration. &#xD;
&#xD;
    {u0, v0, p0} = {u, v, p} /. NDSolve`ProcessSolutions[state]&#xD;
This returns three interpolating functions which are assigned to `u0`, `v0` and `p0`. The velocity field can be visualized using the `StreamPlot` function as showed previously.&#xD;
&#xD;
We will now use the velocity field from the Stokes flow solution as a first guess to solve the N-S equations. We use u0 v0 from the solution of the Stokes flow as an approximation to the solution of the N-S equations:&#xD;
&#xD;
    pde = NSOperator == {0, 0, 0} /. {u[x, y] -&amp;gt; u0[x, y], &#xD;
        v[x, y] -&amp;gt; v0[x, y], re -&amp;gt; 100};&#xD;
Solving the discretized PDEs:&#xD;
&#xD;
    {un, vn, pn} = &#xD;
      NDSolveValue[{pde, bcs}, {u, v, p}, {x, y} \[Element] mesh, &#xD;
       Method -&amp;gt; {&amp;#034;FiniteElement&amp;#034;, &#xD;
         &amp;#034;InterpolationOrder&amp;#034; -&amp;gt; {u -&amp;gt; 2, v -&amp;gt; 2, p -&amp;gt; 1}, &#xD;
         &amp;#034;IntegrationOrder&amp;#034; -&amp;gt; 5}];&#xD;
We can now display the solution of the N-S equations and compare with the Stokes solution:&#xD;
&#xD;
    GraphicsRow[{stokes, &#xD;
      StreamPlot[{un[x, y], vn[x, y]}, {x, 0, 1}, {y, 0, 1}, &#xD;
       StreamPoints -&amp;gt; Fine, StreamColorFunction -&amp;gt; Hue, &#xD;
       StreamColorFunctionScaling -&amp;gt; False, &#xD;
       PlotLabel -&amp;gt; &#xD;
        &amp;#034;Navier-Stokes flow for \!\(\*SubscriptBox[\(R\), \(e\)]\)=100&amp;#034;]},&#xD;
      ImageSize -&amp;gt; Large]&#xD;
![enter image description here][14]&#xD;
&#xD;
This is the first iteration, and we see that the Navier-Stokes flow field is slightly changed compared to the Stokes flow. The flow is not symmetric any more and we can see a new vortex appearing at the lower right corner.&#xD;
&#xD;
Iterating to a converged solution&#xD;
---------------------------------&#xD;
Let&amp;#039;s progress the iteration one more step by assigning the velocity field from the last iteration as an estimate to the solution of the next iteration:&#xD;
&#xD;
    pde = NSOperator == {0, 0, 0} /. {u[x, y] -&amp;gt; un[x, y], &#xD;
        v[x, y] -&amp;gt; vn[x, y], re -&amp;gt; 100};&#xD;
    {state} = &#xD;
      NDSolve`ProcessEquations[{pde, bcs}, {u, v, p}, {x, y} \[Element] &#xD;
        mesh, Method -&amp;gt; {&amp;#034;FiniteElement&amp;#034;, &#xD;
         &amp;#034;InterpolationOrder&amp;#034; -&amp;gt; {u -&amp;gt; 2, v -&amp;gt; 2, p -&amp;gt; 1}, &#xD;
         &amp;#034;IntegrationOrder&amp;#034; -&amp;gt; 5}];&#xD;
    NDSolve`Iterate[state]&#xD;
Extract the velocity field from the last solution and compute the norm:&#xD;
&#xD;
    sol = state[&amp;#034;FiniteElementData&amp;#034;][&amp;#034;Solution&amp;#034;];&#xD;
    uvn = Drop[sol, First[p /. split]];&#xD;
    norm = Norm[uvn - uv0]/Norm[uv0]&#xD;
    &#xD;
    0.0257194&#xD;
In order to visualize the solution of this iteration, we have to process the solution:&#xD;
&#xD;
    {un, vn, pn} = {u, v, p} /. NDSolve`ProcessSolutions[state];&#xD;
&#xD;
    StreamPlot[{un[x, y], vn[x, y]}, {x, 0, 1}, {y, 0, 1}, &#xD;
     StreamPoints -&amp;gt; Fine, StreamColorFunction -&amp;gt; Hue, &#xD;
     StreamColorFunctionScaling -&amp;gt; False, &#xD;
     PlotLabel -&amp;gt; &#xD;
      &amp;#034;Navier-Stokes flow for \!\(\*SubscriptBox[\(R\), \(e\)]\)=100, \&#xD;
    Iteration 2. Norm = &amp;#034; &amp;lt;&amp;gt; ToString[norm]]&#xD;
&#xD;
![enter image description here][15]&#xD;
&#xD;
A norm of more than 2% is not small enough to accept the solution as converged, so we have to proceed with the next iteration:&#xD;
&#xD;
    uvnMinusOne = uvn;&#xD;
    pde = NSOperator == {0, 0, 0} /. {u[x, y] -&amp;gt; un[x, y], &#xD;
        v[x, y] -&amp;gt; vn[x, y], re -&amp;gt; 100};&#xD;
    {state} = &#xD;
      NDSolve`ProcessEquations[{pde, bcs}, {u, v, p}, {x, y} \[Element] &#xD;
        mesh, Method -&amp;gt; {&amp;#034;FiniteElement&amp;#034;, &#xD;
         &amp;#034;InterpolationOrder&amp;#034; -&amp;gt; {u -&amp;gt; 2, v -&amp;gt; 2, p -&amp;gt; 1}, &#xD;
         &amp;#034;IntegrationOrder&amp;#034; -&amp;gt; 5}];&#xD;
    NDSolve`Iterate[state];&#xD;
    sol = state[&amp;#034;FiniteElementData&amp;#034;][&amp;#034;Solution&amp;#034;];&#xD;
    uvn = Drop[sol, First[p /. split]];&#xD;
    norm = Norm[uvn - uvnMinusOne]/Norm[uv0]&#xD;
&#xD;
    {un, vn, pn} = {u, v, p} /. NDSolve`ProcessSolutions[state];&#xD;
&#xD;
    StreamPlot[{un[x, y], vn[x, y]}, {x, 0, 1}, {y, 0, 1}, &#xD;
     StreamPoints -&amp;gt; Fine, StreamColorFunction -&amp;gt; Hue, &#xD;
     StreamColorFunctionScaling -&amp;gt; False, &#xD;
     PlotLabel -&amp;gt; &#xD;
      &amp;#034;\!\(\*SubscriptBox[\(R\), \(e\)]\)=100, Iteration 3. Norm = &amp;#034; &amp;lt;&amp;gt; &#xD;
       ToString[norm]]&#xD;
![enter image description here][16]&#xD;
&#xD;
We see that the norm is  less than 10^-3, and we may accept the last iteration as a converged solution. We have now solved the fully non-linear Navier-Stokes equations for a 2D cavity flow.&#xD;
&#xD;
I hope this small demonstration can be of inspiration to others. The big advantage of using the FE method is the flexibility of the method to discretize non-regular region geometries. This will allow us to solve 2D Navier-Stokes flows for much more complex geometries. I might return with some examples in a future post.&#xD;
&#xD;
Ole Christian&#xD;
&#xD;
&#xD;
  [1]: http://blog.wolfram.com/2013/07/09/using-mathematica-to-simulate-and-visualize-fluid-flow-in-a-box/&#xD;
  [2]: http://community.wolfram.com//c/portal/getImageAttachment?filename=2DNavier-StokesFlow.jpg&amp;amp;userId=382919&#xD;
  [3]: http://community.wolfram.com//c/portal/getImageAttachment?filename=mesh.png&amp;amp;userId=382919&#xD;
  [4]: http://.//blog.wolfram.com/category/high-performance-computing/&#xD;
  [5]: http://community.wolfram.com//c/portal/getImageAttachment?filename=NS.png&amp;amp;userId=382919&#xD;
  [6]: http://community.wolfram.com//c/portal/getImageAttachment?filename=NS2.png&amp;amp;userId=382919&#xD;
  [7]: http://community.wolfram.com//c/portal/getImageAttachment?filename=Linearisation.png&amp;amp;userId=382919&#xD;
  [8]: http://community.wolfram.com//c/portal/getImageAttachment?filename=Tolerance.png&amp;amp;userId=382919&#xD;
  [9]: http://community.wolfram.com//c/portal/getImageAttachment?filename=eps.png&amp;amp;userId=382919&#xD;
  [10]: http://community.wolfram.com//c/portal/getImageAttachment?filename=uk.png&amp;amp;userId=382919&#xD;
  [11]: http://community.wolfram.com//c/portal/getImageAttachment?filename=u0.png&amp;amp;userId=382919&#xD;
  [12]: http://community.wolfram.com//c/portal/getImageAttachment?filename=StokesFlow.png&amp;amp;userId=382919&#xD;
  [13]: http://community.wolfram.com//c/portal/getImageAttachment?filename=StokesSolution.png&amp;amp;userId=382919&#xD;
  [14]: http://community.wolfram.com//c/portal/getImageAttachment?filename=NS1andStokes.png&amp;amp;userId=382919&#xD;
  [15]: http://community.wolfram.com//c/portal/getImageAttachment?filename=NS2Sol.png&amp;amp;userId=382919&#xD;
  [16]: http://community.wolfram.com//c/portal/getImageAttachment?filename=NS3Sol.png&amp;amp;userId=382919</description>
    <dc:creator>Ole Christian Astrup</dc:creator>
    <dc:date>2015-11-11T15:12:37Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/611304">
    <title>FEM Solver for Navier-Stokes equations in 2D</title>
    <link>https://community.wolfram.com/groups/-/m/t/611304</link>
    <description>I&amp;#039;ll show how to use the low level FEM functionality to code up a non-linear Navier-Stokes solver. The documentation explains the details about the low level [FEM programming](http://reference.wolfram.com/language/FEMDocumentation/tutorial/FiniteElementProgramming.html) functionality which I use here.&#xD;
&#xD;
Here is the basic idea: After every non-linear iteration we re-create an interpolation function from the now current solution vector and re-insert those into the PDE coefficients and iterate until converged. This will not be insanely efficient but it works on a PDE level. Now, to tackle non-linear problems it&amp;#039;s a good idea to get the linear version to work first. In this case this is a Stokes solver.&#xD;
&#xD;
Here is a utility function to convert a PDE into it&amp;#039;s discretized version:&#xD;
&#xD;
    Needs[&amp;#034;NDSolve`FEM`&amp;#034;]&#xD;
    PDEtoMatrix[{pde_, ?___}, u_, r__] := &#xD;
     Module[{ndstate, feData, sd, bcData, methodData, pdeData},&#xD;
      {ndstate} =&#xD;
       NDSolve`ProcessEquations[Flatten[{pde, ?}], u, &#xD;
        Sequence @@ {r}];&#xD;
      sd = ndstate[&amp;#034;SolutionData&amp;#034;][[1]];&#xD;
      feData = ndstate[&amp;#034;FiniteElementData&amp;#034;];&#xD;
      pdeData = feData[&amp;#034;PDECoefficientData&amp;#034;];&#xD;
      bcData = feData[&amp;#034;BoundaryConditionData&amp;#034;];&#xD;
      methodData = feData[&amp;#034;FEMMethodData&amp;#034;];&#xD;
      {DiscretizePDE[pdeData, methodData, sd], &#xD;
       DiscretizeBoundaryConditions[bcData, methodData, sd], sd, &#xD;
       methodData}&#xD;
      ]&#xD;
&#xD;
Next is the problem setup:&#xD;
&#xD;
    ? = 10^-3;&#xD;
    ? = 1;&#xD;
    l = 2.2;&#xD;
    h = 0.41;&#xD;
    ? = &#xD;
      RegionDifference[Rectangle[{0, 0}, {l, h}], &#xD;
       ImplicitRegion[(x - 1/5)^2 + (y - 1/5)^2 &amp;lt; (1/20)^2, {x, y}]];&#xD;
    RegionPlot[?, AspectRatio -&amp;gt; Automatic]&#xD;
&#xD;
[![enter image description here][1]][2]&#xD;
&#xD;
    ? = {&#xD;
       DirichletCondition[p[x, y] == 0., x == l],&#xD;
       DirichletCondition[{u[x, y] == 4*0.3*y*(h - y)/h^2, v[x, y] == 0}, &#xD;
        x == 0],&#xD;
       DirichletCondition[{u[x, y] == 0., v[x, y] == 0.}, &#xD;
        y == 0 || y == h || (x - 1/5)^2 + (y - 1/5)^2 &amp;lt;= (1/20)^2]};&#xD;
    stokes = {&#xD;
       D[u[x, y], x] + D[v[x, y], y],&#xD;
       Div[{{-?, 0}, {0, -?}}.Grad[u[x, y], {x, y}], {x, y}] + &#xD;
        D[p[x, y], x],&#xD;
       Div[{{-?, 0}, {0, -?}}.Grad[v[x, y], {x, y}], {x, y}] + &#xD;
        D[p[x, y], y]&#xD;
       };&#xD;
&#xD;
First we generate the system matrices for the Stokes equation:&#xD;
&#xD;
    {dPDE, dBC, sd, md} = &#xD;
      PDEtoMatrix[{stokes == {0, 0, 0}, ?}, {p, u, &#xD;
        v}, {x, y} ? ?, &#xD;
       Method -&amp;gt; {&amp;#034;FiniteElement&amp;#034;, &#xD;
         &amp;#034;InterpolationOrder&amp;#034; -&amp;gt; {p -&amp;gt; 1, u -&amp;gt; 2, v -&amp;gt; 2}, &#xD;
         &amp;#034;MeshOptions&amp;#034; -&amp;gt; {&amp;#034;ImproveBoundaryPosition&amp;#034; -&amp;gt; False}}];&#xD;
&#xD;
    linearLoad = dPDE[&amp;#034;LoadVector&amp;#034;];&#xD;
    linearStiffness = dPDE[&amp;#034;StiffnessMatrix&amp;#034;];&#xD;
    vd = md[&amp;#034;VariableData&amp;#034;];&#xD;
    offsets = md[&amp;#034;IncidentOffsets&amp;#034;];&#xD;
&#xD;
You could solve this stationary case, but we move on: The tricky part for non-linear equations is the linearization. For that I am referring you to [Chapter 5](https://www.freidok.uni-freiburg.de/fedora/objects/freidok:6440/datastreams/FILE1/content).&#xD;
&#xD;
    &#xD;
    uOld = ConstantArray[{0.}, md[&amp;#034;DegreesOfFreedom&amp;#034;]];&#xD;
    mesh2 = md[&amp;#034;ElementMesh&amp;#034;];&#xD;
    mesh1 = MeshOrderAlteration[mesh2, 1];&#xD;
    &#xD;
    ClearAll[rhs]&#xD;
    rhs[t_?NumericQ, ut_] := Module[{uOld},&#xD;
      uOld = ut;&#xD;
      Do[&#xD;
       ClearAll[u0, v0, p0];&#xD;
       (* create pressure and velocity interpolations *)&#xD;
       p0 = ElementMeshInterpolation[{mesh1}, &#xD;
         uOld[[offsets[[1]] + 1 ;; offsets[[2]]]]];&#xD;
       u0 = ElementMeshInterpolation[{mesh2}, &#xD;
         uOld[[offsets[[2]] + 1 ;; offsets[[3]]]]];&#xD;
       v0 = ElementMeshInterpolation[{mesh2}, &#xD;
         uOld[[offsets[[3]] + 1 ;; offsets[[4]]]]];&#xD;
       &#xD;
       (* these are the linearized coefficients *)&#xD;
       nlPdeCoeff = InitializePDECoefficients[vd, sd,&#xD;
         &amp;#034;LoadCoefficients&amp;#034; -&amp;gt; {(* &#xD;
           F *)&#xD;
           {-(D[u0[x, y], x] + D[v0[x, y], y])},&#xD;
           {-? (u0[x, y]*D[u0[x, y], x] + v0[x, y]*D[u0[x, y], y]) - &#xD;
             D[p0[x, y], x]},&#xD;
           {-? (u0[x, y]*D[v0[x, y], x] + v0[x, y]*D[v0[x, y], y]) - &#xD;
             D[p0[x, y], y]}&#xD;
           },&#xD;
         &amp;#034;LoadDerivativeCoefficients&amp;#034; -&amp;gt; -{(* gamma *)&#xD;
            {{0, 0}},&#xD;
            {{? D[u0[x, y], x], ? D[u0[x, y], y]}},&#xD;
            {{? D[v0[x, y], x], ? D[v0[x, y], y]}}&#xD;
            },&#xD;
         &amp;#034;ConvectionCoefficients&amp;#034; -&amp;gt; {(*beta*)&#xD;
           {{{0, 0}}, {{0, &#xD;
              0}}, {{0, 0}}},&#xD;
           {{{0, 0}}, {{? u0[x, y], ? v0[x, y]}}, {{0, 0}}},&#xD;
           {{{0, 0}}, {{0, 0}}, {{? u0[x, y], ? v0[x, y]}}}&#xD;
           },&#xD;
         &amp;#034;ReactionCoefficients&amp;#034; -&amp;gt; {(* a *)&#xD;
           {0, 0, 0},&#xD;
           {0, ? D[u0[x, y], x], ? D[u0[x, y], y]},&#xD;
           {0, ? D[v0[x, y], x], ? D[v0[x, y], y]}&#xD;
           }&#xD;
         ];&#xD;
       &#xD;
       nlsys = DiscretizePDE[nlPdeCoeff, md, sd];&#xD;
       nlLoad = nlsys[&amp;#034;LoadVector&amp;#034;];&#xD;
       nlStiffness = nlsys[&amp;#034;StiffnessMatrix&amp;#034;];&#xD;
       &#xD;
       ns = nlStiffness + linearStiffness;&#xD;
       nl = nlLoad + linearLoad;&#xD;
       &#xD;
       DeployBoundaryConditions[{nl, ns}, dBC];&#xD;
       diriPos = dBC[&amp;#034;DirichletRows&amp;#034;];&#xD;
       nl[[ diriPos ]] = nl[[ diriPos ]] - uOld[[diriPos]];&#xD;
       &#xD;
       dU = LinearSolve[ns, nl];&#xD;
       Print[ i, &amp;#034; Residual: &amp;#034;, Norm[nl, Infinity], &amp;#034;  Correction: &amp;#034;, &#xD;
        Norm[ dU, Infinity ]];&#xD;
       uOld = uOld + dU;&#xD;
       &#xD;
       (*If[Norm[ dU, Infinity ]&amp;lt;10^-6,Break[]];*)&#xD;
       &#xD;
       , {i, 8}&#xD;
       ];&#xD;
      uOld&#xD;
      ]&#xD;
&#xD;
You&amp;#039;d then run this:&#xD;
&#xD;
    uNew = rhs[0, uOld];&#xD;
&#xD;
    1 Residual: 0.3  Correction: 0.387424&#xD;
    2 Residual: 0.000752321  Correction: 0.184443&#xD;
    3 Residual: 0.00023243  Correction: 0.0368286&#xD;
    4 Residual: 0.0000100488  Correction: 0.00264305&#xD;
    5 Residual: 3.6416*10^-8  Correction: 0.0000115344&#xD;
    6 Residual: 8.88314*10^-13  Correction: 1.22413*10^-10&#xD;
    7 Residual: 1.50704*10^-17  Correction: 1.08287*10^-15&#xD;
    8 Residual: 1.24246*10^-17  Correction: 6.93036*10^-16&#xD;
&#xD;
See that the residual and correction converge. And do some post processing:&#xD;
&#xD;
    p0 = ElementMeshInterpolation[{mesh1}, &#xD;
       uNew[[offsets[[1]] + 1 ;; offsets[[2]]]]];&#xD;
    u0 = ElementMeshInterpolation[{mesh2}, &#xD;
       uNew[[offsets[[2]] + 1 ;; offsets[[3]]]]];&#xD;
    v0 = ElementMeshInterpolation[{mesh2}, &#xD;
       uNew[[offsets[[3]] + 1 ;; offsets[[4]]]]];&#xD;
    ContourPlot[u0[x, y], {x, y} ? mesh2, &#xD;
     AspectRatio -&amp;gt; Automatic, PlotRange -&amp;gt; All, &#xD;
     ColorFunction -&amp;gt; ColorData[&amp;#034;TemperatureMap&amp;#034;], Contours -&amp;gt; 10, &#xD;
     ImageSize -&amp;gt; Large]&#xD;
    ContourPlot[v0[x, y], {x, y} ? mesh2, &#xD;
     AspectRatio -&amp;gt; Automatic, PlotRange -&amp;gt; All, &#xD;
     ColorFunction -&amp;gt; ColorData[&amp;#034;TemperatureMap&amp;#034;], Contours -&amp;gt; 10, &#xD;
     ImageSize -&amp;gt; Large]&#xD;
    ContourPlot[p0[x, y], {x, y} ? mesh1, &#xD;
     AspectRatio -&amp;gt; Automatic, PlotRange -&amp;gt; All, &#xD;
     ColorFunction -&amp;gt; ColorData[&amp;#034;TemperatureMap&amp;#034;], Contours -&amp;gt; 10, &#xD;
     ImageSize -&amp;gt; Large]&#xD;
&#xD;
[![enter image description here][3]][4]&#xD;
[![enter image description here][5]][6]&#xD;
[![enter image description here][7]][8]&#xD;
&#xD;
Which show the x-, y-velocity components and the pressure.&#xD;
&#xD;
&#xD;
----------&#xD;
&#xD;
*This is a re-post of the [original][9] made with authors permission.*&#xD;
&#xD;
&#xD;
  [1]: http://i.stack.imgur.com/8yr5F.jpg&#xD;
  [2]: http://i.stack.imgur.com/8yr5F.jpg&#xD;
  [3]: http://i.stack.imgur.com/oTeq0.jpg&#xD;
  [4]: http://i.stack.imgur.com/oTeq0.jpg&#xD;
  [5]: http://i.stack.imgur.com/k6rjY.jpg&#xD;
  [6]: http://i.stack.imgur.com/k6rjY.jpg&#xD;
  [7]: http://i.stack.imgur.com/AcnxA.jpg&#xD;
  [8]: http://i.stack.imgur.com/AcnxA.jpg&#xD;
  [9]: http://mathematica.stackexchange.com/a/96579/13</description>
    <dc:creator>EDITORIAL BOARD</dc:creator>
    <dc:date>2015-11-12T18:24:33Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/136774">
    <title>Heat Transfer Problem</title>
    <link>https://community.wolfram.com/groups/-/m/t/136774</link>
    <description>Hi, im currently trying to work on the following formulae for a 1-d transient Heat transfer problem.

[img=width: 272px; height: 74px;]/c/portal/getImageAttachment?filename=ScreenShot2013-10-10at1.58.06AM.png&amp;amp;userId=136759[/img]


Basically it is a bar with 2 ends where each end has a fixed temperature after t=0 meaning to say that one end is being heated while the other is cooled to a fixed temperature.[b] i want to get a sketch of temp vs time and the solution for dT/dt[/b]

my boundary condtions are
T(0,0)=301K=T(L,0)
and when it reaches steady state at an unknown time, 
T(0,t)=293
T(L,t)=473

so with L = 5 i tried solving the equation but i kept coming up with the same error.

[b]heatsol = 
 NDSolve[{3.25D[temp[x, t], t] == -0.0000447D[
      temp[x, t], {x, 2}], temp[0, 0] == 301, temp[5, 0] == 301, 
   temp[5, t] == 473}, temp, {x, 0, 5}, {t, 0, 100}][/b]

NDSolve::deqn: Equation or list of equations expected instead of True in the first argument {3.24776 (temp^(0,1))[x,t]==-0.000044705 (temp^(2,0))[x,t],temp[0,0]==301,temp[5,0]==301,True,temp[0,t]==273}. &amp;gt;&amp;gt;

but if i assigned a random number to the boundary condition where it reaches steady state, temp[5,100] i get the following error saying that my initial condition is redundant

[b]heatsol = 
 NDSolve[{3.247755102 D[temp[x, t], t] == -0.000044705030299999997 D[
      temp[x, t], {x, 2}], temp[5, 0] == 301, temp[5, 100] == 473}, 
  temp, {x, 0, 5}, {t, 0, 100}][/b]

NDSolve::bcedge: Boundary condition temp[5,0]==301 is not specified on a single edge of the boundary of the computational domain. &amp;gt;&amp;gt;</description>
    <dc:creator>Jon T</dc:creator>
    <dc:date>2013-10-09T18:14:37Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/1843550">
    <title>Mandelbrot Set on Neural Network</title>
    <link>https://community.wolfram.com/groups/-/m/t/1843550</link>
    <description>*MODERATOR NOTE: a submission to computations art contest, see more:* https://wolfr.am/CompArt-22&#xD;
&#xD;
----------&#xD;
&#xD;
Showing Abs and Arg fields of Mandelbrot set under 200 iterations&#xD;
&#xD;
![Mandelbrot_wallpaper.png][1]&#xD;
&#xD;
---&#xD;
&#xD;
Showing Abs field of Mandelbrot set under 9 iterations&#xD;
&#xD;
![9_iteration_abs.png][2]&#xD;
&#xD;
---&#xD;
&#xD;
Showing Re vs. Im complex mapping of Mandelbrot set under 200 iterations&#xD;
&#xD;
![ReIm_Complex_map.png][3]&#xD;
&#xD;
---&#xD;
&#xD;
Mandelbrot Set on Neural Network&#xD;
===========================================&#xD;
&#xD;
[The MXNet-based neural network framework](http://reference.wolfram.com/language/guide/NeuralNetworks.html) has been introduced to Wolfram Language since version 11. It is mostly designed for deep learning. However if we think about it, neural network is merely another fancy way to implement a certain program. As more and more functions are supported, it is now possible for us to &amp;#034;compile&amp;#034; general numerical program to neural network, which essentially gives us an interface to GPGPU parallel ability without the hassle of low-level coding.&#xD;
&#xD;
Inspired by [Brian](https://community.wolfram.com/web/tl2854)&amp;#039;s [recent post on MathCompile](https://community.wolfram.com/groups/-/m/t/1830592), we demonstrate in this post how to implement a neural network to compute the Mandelbrot set.&#xD;
&#xD;
## Utilities&#xD;
&#xD;
As usual here is the code dump of some helper functions. Readers can evaluate then safely skip this section.&#xD;
&#xD;
### code dump of helper functions&#xD;
&#xD;
```&#xD;
ClearAll[pipe, branch]&#xD;
pipe   = RightComposition;&#xD;
branch = Through@*{##} &amp;amp;;&#xD;
```&#xD;
```&#xD;
Needs[&amp;#034;NeuralNetworks`&amp;#034;]&#xD;
```&#xD;
```&#xD;
Clear[netInputPortSort]&#xD;
netInputPortSort[inPortLst_List] := Function[origNet, netInputPortSort[origNet, inPortLst]]&#xD;
netInputPortSort[origNet_NetGraph, inPortLst_List] :=&#xD;
 Block[{NetGraph = Inactive[NetGraph], fullnet, net},&#xD;
           fullnet         = origNet&#xD;
           ; net           = fullnet[[1]]&#xD;
           ; net[&amp;#034;Inputs&amp;#034;] = AssociationThread[Rule[inPortLst, inPortLst /. net[&amp;#034;Inputs&amp;#034;]]]&#xD;
           ; ReplacePart[fullnet, 1 -&amp;gt; net]&#xD;
      ] // Activate&#xD;
```&#xD;
&#xD;
---&#xD;
&#xD;
# Basic concept&#xD;
&#xD;
The center of the Mandelbrot set computation is a simple iteration:&#xD;
&#xD;
$$\left\{&#xD;
\begin{align}&#xD;
 z_n &amp;amp;= c+z_{n-1}^2 \\&#xD;
 z_0 &amp;amp;= 0&#xD;
\end{align}&#xD;
\right.$$&#xD;
&#xD;
Under simple iteration it leads to the Mandelbrot set.&#xD;
&#xD;
```&#xD;
Block[{region, c, faclets}&#xD;
         ,&#xD;
         (* random-points as different c for iteration: *)&#xD;
         region = Disk[{-.5, 0}, 2] // DiscretizeGraphics // DiscretizeRegion[#, MaxCellMeasure -&amp;gt; .0001] &amp;amp;&#xD;
         ; faclets = MeshCells[region, 2][[;; , 1]]&#xD;
         ; c = MeshCoordinates[region].{1, I}&#xD;
         ;(* The iteration taking place simultaneously for all c, nested 21 steps: *)&#xD;
         Nest[Function[z, z^2 + c], 0, 21] //&#xD;
              (* Visualizing the result: *)&#xD;
              pipe[&#xD;
                      pipe[(* Regularizing the norm for a clear visualization: *)&#xD;
                           Abs, HistogramTransform, Rescale, (1 - #)^2 &amp;amp;]&#xD;
                      , Append[ReIm[c]\[Transpose], #]\[Transpose] &amp;amp;&#xD;
                      , Graphics3D[&#xD;
                                    GraphicsComplex[#, {EdgeForm[], Polygon@faclets}]&#xD;
                                    , Boxed -&amp;gt; False, SphericalRegion -&amp;gt; True, RotationAction -&amp;gt; &amp;#034;Fit&amp;#034;&#xD;
                                    , ViewPoint -&amp;gt; {1, -2.4, 2.4}, ViewVertical -&amp;gt; {0, 0, 1}&#xD;
                                  ] &amp;amp;&#xD;
                  ]&#xD;
     ]&#xD;
```&#xD;
&#xD;
![3D mesh of Mandelbrot set][4]&#xD;
&#xD;
Using the built-in [`MandelbrotSetPlot`](http://reference.wolfram.com/language/ref/MandelbrotSetPlot.html) function, it&amp;#039;s straightforward to plot the traditional Mandelbrot set visualization:&#xD;
&#xD;
```&#xD;
MandelbrotSetPlot[{-2.5 - 2 I, 1.5 + 2 I}]&#xD;
```&#xD;
&#xD;
![MandelbrotSetPlot][5]&#xD;
&#xD;
With some test we can notice that, for fixed `MaxIterations`, the relationship between computing time of `MandelbrotSetPlot` and `ImageResolution` follows a power law.&#xD;
&#xD;
```&#xD;
builtInTimeTest = {#, AbsoluteTiming[MandelbrotSetPlot[{-2.5 - 2 I, 1.5 + 2 I}, MaxIterations -&amp;gt; 100, ImageResolution -&amp;gt; #];][[1]]} &amp;amp; /@ Range[101, 4001, 100]&#xD;
&#xD;
NonlinearModelFit[builtInTimeTest, a r^k, {a, k}, r][r] //&#xD;
  LogLogPlot[#, {r, 400, 5000}, PlotStyle -&amp;gt; Directive[Red, AbsoluteThickness[2]], Frame -&amp;gt; True, FrameTicks -&amp;gt; All] &amp;amp; //&#xD;
  Show[{#&#xD;
        , ListLogLogPlot[builtInTimeTest, PlotMarkers -&amp;gt; &amp;#034;OpenMarkers&amp;#034;, PlotRange -&amp;gt; All]&#xD;
        }, FrameLabel -&amp;gt; {&amp;#034;ImageResolution&amp;#034;, &amp;#034;AbsoluteTiming&amp;#034;}] &amp;amp;&#xD;
```&#xD;
&#xD;
![time benchmark of MandelbrotSetPlot][6]&#xD;
&#xD;
This is a scenario where parallel computation might make a difference.&#xD;
&#xD;
---&#xD;
&#xD;
# Mandelbrot set on neural network -- A naïve attempt&#xD;
&#xD;
## The implementation&#xD;
&#xD;
### Iteration core net&#xD;
&#xD;
Neural network (short for **_NN_**) doesn&amp;#039;t support complex number (yet). Aside from that, the iteration formula is simple enough for [`ThreadingLayer`](http://reference.wolfram.com/language/ref/ThreadingLayer.html):&#xD;
&#xD;
```&#xD;
iterNet = Module[{c = cX + cY I, z = x + y I},&#xD;
  z^2 + c // pipe[&#xD;
                    ReIm, ComplexExpand, Echo[#, &amp;#034;{Re[\!\(\*SuperscriptBox[\(z\), \(2\)]\)+c], Im[\!\(\*SuperscriptBox[\(z\), \(2\)]\)+c]}:&amp;#034;] &amp;amp;&#xD;
                    , Map@pipe[&#xD;
                                 Inactive[Function][{cX, cY, x, y}, #] &amp;amp;&#xD;
                                 , Activate&#xD;
                                 , ThreadingLayer&#xD;
                              ]&#xD;
                    , Inactive[NetGraph][#&#xD;
                                            , {&#xD;
                                                   (NetPort /@ StringSplit[&amp;#034;cX,cY,x,y&amp;#034;, &amp;#034;,&amp;#034;]) -&amp;gt; # &amp;amp; /@ {1, 2}&#xD;
                                                   , 1 -&amp;gt; NetPort[&amp;#034;x&amp;#034;], 2 -&amp;gt; NetPort[&amp;#034;y&amp;#034;]&#xD;
                                              }&#xD;
                                        ] &amp;amp;&#xD;
                    , Activate&#xD;
                 ]&#xD;
  ]&#xD;
```&#xD;
&#xD;
![iterNet][7]&#xD;
&#xD;
It&amp;#039;s very easy to perform the iteration with the help of [`Nest`](http://reference.wolfram.com/language/ref/Nest.html) / [`NestList`](http://reference.wolfram.com/language/ref/NestList.html).&#xD;
&#xD;
```&#xD;
Block[{region, c, xyInit, result}&#xD;
         ,&#xD;
         (* random-points as different c for iteration: *)&#xD;
         region = Disk[{0, 0}, .5] // DiscretizeGraphics // DiscretizeRegion[#, MaxCellMeasure -&amp;gt; .01] &amp;amp;&#xD;
         ; c = MeshCoordinates[region].{1, I} // ReIm&#xD;
         ; c = AssociationThread[StringSplit[&amp;#034;cX,cY&amp;#034;, &amp;#034;,&amp;#034;], c\[Transpose]]&#xD;
         ; xyInit = AssociationThread[StringSplit[&amp;#034;x,y&amp;#034;, &amp;#034;,&amp;#034;], 0*Values[c]]&#xD;
         ; result = NestList[&#xD;
                                pipe[&#xD;
                                      Map[Clip[#, {-2, 2}] &amp;amp;]&#xD;
                                      , Join[c, #] &amp;amp;&#xD;
                                      , iterNet&#xD;
                                    ]&#xD;
                                , xyInit, 20&#xD;
                            ]&#xD;
         ; result //&#xD;
             pipe[&#xD;
                     Values, Rest, Map@Transpose&#xD;
                     , Transpose&#xD;
                     , MapThread[{#2, BSplineCurve@#1} &amp;amp;, {#, # // Length // Range // N // Rescale // Map[ColorData[&amp;#034;Rainbow&amp;#034;]]}] &amp;amp;&#xD;
                     , Graphics[#, Frame -&amp;gt; True, FrameTicks -&amp;gt; All, PlotRange -&amp;gt; {GoldenRatio {-1, 1}, {-1, 1}}, PlotRangeClipping -&amp;gt; True] &amp;amp;&#xD;
                 ]&#xD;
     ]&#xD;
```&#xD;
&#xD;
![Nest on iterNet][8]&#xD;
&#xD;
### Nest net&#xD;
&#xD;
Now we have the core net representing the iteration formula, we need to mimic the functionality of `Nest[f, expr, n]` fully on a neural network.&#xD;
&#xD;
The go-to function is of course [`NetNestOperator`](https://reference.wolfram.com/language/ref/NetNestOperator.html). However in our case, the same $c$ is used repeatedly for all iterations, so we&amp;#039;d like to pass it directly to each iteration. Thus, we do it with the following customized `NetNestPartialOperator` function:&#xD;
&#xD;
```&#xD;
ClearAll[NetNestPartialOperator]&#xD;
NetNestPartialOperator[net_, staticPorts_List, nestPort_, iterNum_Integer] :=&#xD;
 Module[{pIdx, netIdx, staticpath, nestpath},&#xD;
  netIdx = Range[iterNum]&#xD;
  ; pIdx = AssociationThread[staticPorts, staticPorts // Length // Range // Map[ToString]]&#xD;
  ; staticpath = Function[p, NetPort[&amp;#034;static&amp;#034; &amp;lt;&amp;gt; pIdx[p]] -&amp;gt; (NetPort[#, p] &amp;amp; /@ netIdx)] /@ staticPorts&#xD;
  ; nestpath = Thread[Flatten[{NetPort[&amp;#034;nest&amp;#034;], netIdx // Most}] -&amp;gt; (NetPort[#, nestPort] &amp;amp; /@ netIdx)]&#xD;
  ; Inactive[NetGraph][ConstantArray[net, iterNum], {staticpath, nestpath} // Flatten] //&#xD;
       Activate // &#xD;
       netInputPortSort[Flatten[{&amp;#034;nest&amp;#034;, &amp;#034;static&amp;#034; &amp;lt;&amp;gt; # &amp;amp; /@ Values[pIdx]}]]&#xD;
  ]&#xD;
```&#xD;
&#xD;
Basically our `NetNestPartialOperator` takes a [`net_NetGraph`](https://reference.wolfram.com/language/ref/NetGraph.html) as the 1st argument. One of `net`&amp;#039;s input ports, i.e. `nestPort`, is going to be nested across iterations; other input ports (i.e. `staticPorts`) will be feed in constant/non-nested values.&#xD;
&#xD;
Here is a simple example realizing a 5 steps nest iteration `Nest[Function[c,a+b+c],c0,5]`:&#xD;
&#xD;
```&#xD;
Module[{coreNet, nestNet}&#xD;
           , coreNet = NetGraph[{ThreadingLayer[#1+#2+#3&amp;amp;]}, {{NetPort[&amp;#034;a&amp;#034;],NetPort[&amp;#034;b&amp;#034;],NetPort[&amp;#034;c&amp;#034;]}-&amp;gt;1},&amp;#034;a&amp;#034;-&amp;gt;&amp;#034;Real&amp;#034;,&amp;#034;b&amp;#034;-&amp;gt;&amp;#034;Real&amp;#034;,&amp;#034;c&amp;#034;-&amp;gt;&amp;#034;Real&amp;#034;]&#xD;
           ; nestNet = NetNestPartialOperator[coreNet, {&amp;#034;a&amp;#034;, &amp;#034;b&amp;#034;}, &amp;#034;c&amp;#034;, 5]&#xD;
           ; {&#xD;
               {&amp;#034;coreNet&amp;#034;, &amp;#034;nestNet&amp;#034;}&#xD;
               , Quiet[&#xD;
                         NetInformation[#, &amp;#034;MXNetNodeGraph&amp;#034;] // Graph[#, VertexSize -&amp;gt; 0.2, VertexLabels -&amp;gt; &amp;#034;Name&amp;#034;] &amp;amp;&#xD;
                      ] &amp;amp; /@ {coreNet, nestNet}&#xD;
             }\[Transpose] // &#xD;
             Grid[#, Background -&amp;gt; {{GrayLevel[.9], None}, None}, Frame -&amp;gt; All, FrameStyle -&amp;gt; Black] &amp;amp;&#xD;
      ]&#xD;
```&#xD;
&#xD;
![NetNestPartialOperator example][9]&#xD;
&#xD;
### The Mandelbrot net&#xD;
&#xD;
In order to construct a net suitable for `NetNestPartialOperator`, we merge the real and imaginary ports in `iterNet` into a single &amp;#034;complex&amp;#034; port.&#xD;
&#xD;
```&#xD;
zNet = NetGraph[{ReplicateLayer[1], ReplicateLayer[1], CatenateLayer[]}, {NetPort[&amp;#034;1&amp;#034;] -&amp;gt; 1, NetPort[&amp;#034;2&amp;#034;] -&amp;gt; 2, {1, 2} -&amp;gt; 3}];&#xD;
&#xD;
nestcoreNet = NetGraph[&#xD;
                        {PartLayer[1], PartLayer[2], iterNet, zNet}&#xD;
                        , {&#xD;
                               (NetPort[#] -&amp;gt; NetPort[3, #]) &amp;amp; /@ StringSplit[&amp;#034;cX,cY&amp;#034;, &amp;#034;,&amp;#034;]&#xD;
                             , NetPort[&amp;#034;z&amp;#034;] -&amp;gt; {1, 2}&#xD;
                             , {{1, 2}, StringSplit[&amp;#034;x,y&amp;#034;, &amp;#034;,&amp;#034;]} // MapThread[(#1 -&amp;gt; NetPort[3, #2]) &amp;amp;]&#xD;
                             , {StringSplit[&amp;#034;x,y&amp;#034;, &amp;#034;,&amp;#034;], StringSplit[&amp;#034;1,2&amp;#034;, &amp;#034;,&amp;#034;]} // MapThread[(NetPort[3, #1] -&amp;gt; NetPort[4, #2]) &amp;amp;]&#xD;
                          }&#xD;
                      ]&#xD;
```&#xD;
&#xD;
![nestcoreNet][10]&#xD;
&#xD;
Thus a full net computing the Mandelbrot set is constructed as follows:&#xD;
&#xD;
```&#xD;
ClearAll[mandelbrot]&#xD;
mandelbrot[iterNum_Integer?Positive] :=&#xD;
     NetGraph[{&#xD;
                  zNet&#xD;
                , ElementwiseLayer[0 # &amp;amp;]&#xD;
                , NetNestPartialOperator[nestcoreNet, StringSplit[&amp;#034;cX,cY&amp;#034;, &amp;#034;,&amp;#034;], &amp;#034;z&amp;#034;, iterNum]&#xD;
              }, {&#xD;
                  {NetPort[&amp;#034;cX&amp;#034;], NetPort[&amp;#034;cY&amp;#034;]} -&amp;gt; 1 -&amp;gt; 2&#xD;
                , {2, NetPort[&amp;#034;cX&amp;#034;], NetPort[&amp;#034;cY&amp;#034;]} -&amp;gt; 3&#xD;
              }&#xD;
             ]&#xD;
```&#xD;
&#xD;
## Results&#xD;
&#xD;
We showcase our `mandelbrot` net with 9 iteration steps over the complex region ${-2-1.2I,1+1.2I}$, with a image resolution $401 \times 501$. The network is executed on a GPU (NVIDIA GeForce GTX 1050 Ti) with [`&amp;#034;Real64&amp;#034;`](https://reference.wolfram.com/language/ref/NetGraph.html#1010560149) precision.&#xD;
&#xD;
```&#xD;
mandelbrotF = mandelbrot[9];&#xD;
```&#xD;
```&#xD;
result =&#xD;
  Module[{region = {-2 - 1.2 I, 1 + 1.2 I}, resol = 501, aspr},&#xD;
         region = region // ReIm // Transpose&#xD;
         ; aspr = region.{-1, 1} // Reverse // Apply[Divide]&#xD;
         ; resol = resol {1, aspr} // Round&#xD;
         ; {resol, region} //&#xD;
             pipe[&#xD;
                   MapThread[Rescale[Range[#1] // N // Rescale, {0, 1}, #2] &amp;amp;]&#xD;
                   , Tuples&#xD;
                   , AssociationThread[{&amp;#034;cX&amp;#034;, &amp;#034;cY&amp;#034;}, #\[Transpose]] &amp;amp;&#xD;
                   , AbsoluteTiming[mandelbrotF[#, WorkingPrecision -&amp;gt; &amp;#034;Real64&amp;#034;, TargetDevice -&amp;gt; &amp;#034;GPU&amp;#034;]] &amp;amp;&#xD;
                   , pipe[&#xD;
                            branch[pipe[First, Quantity[#, &amp;#034;Seconds&amp;#034;] &amp;amp;, Echo[#, &amp;#034;Computing time on NN:&amp;#034;] &amp;amp;], Last]&#xD;
                            , Last]&#xD;
                   , Developer`ToPackedArray&#xD;
                   , ArrayReshape[#, {2, Sequence @@ resol}] &amp;amp;&#xD;
                   , {1, I}.# &amp;amp;&#xD;
                   , Transpose, Reverse&#xD;
                 ]&#xD;
        ];&#xD;
&#xD;
(* Computing time on NN: 3.08505 s *)&#xD;
```&#xD;
```&#xD;
result // Dimensions&#xD;
(* {401, 501} *)&#xD;
```&#xD;
```&#xD;
result //&#xD;
   pipe[&#xD;
         branch[&#xD;
                 pipe[ Abs&#xD;
                     , pipe[&#xD;
                             branch[Flatten /* HistogramTransform, Dimensions /* Last]&#xD;
                           , Apply@Partition&#xD;
                           ]&#xD;
                     , Rescale, (1 - #)^5 &amp;amp;&#xD;
                     ]&#xD;
               , pipe[Arg, Sin, Rescale]&#xD;
               ]&#xD;
       , Map @ pipe[&#xD;
                     Image[#, ImageSize -&amp;gt; Length[#]] &amp;amp;&#xD;
                   , Colorize[#, ColorFunction -&amp;gt; &amp;#034;DarkColorFractalGradient&amp;#034;] &amp;amp;&#xD;
                   ]&#xD;
       ]&#xD;
```&#xD;
&#xD;
![naive result][11]&#xD;
&#xD;
Note the highlighted [periodic bulbs and Mandelbrot dendritic islands](https://dhushara.com/DarkHeart/DarkHeart.htm) in the left image, and the pattern approximately following the [external rays](https://en.wikipedia.org/wiki/External_ray) of the set in the right image.&#xD;
&#xD;
As a comparison, here is the result from the same region, iteration steps and resolution using the built-in `MandelbrotSetPlot` function.&#xD;
&#xD;
```&#xD;
AbsoluteTiming[&#xD;
                MandelbrotSetPlot[{-2 - 1.2 I, 1 + 1.2 I}, MaxIterations -&amp;gt; 9, ImageResolution -&amp;gt; 501]&#xD;
              ] //&#xD;
     pipe[&#xD;
           branch[pipe[First, Quantity[#, &amp;#034;Seconds&amp;#034;] &amp;amp;, Echo[#, &amp;#034;Computing time:&amp;#034;] &amp;amp;], Last], Last&#xD;
         , #[[1, 1]] &amp;amp;, Reverse, Image[#, ImageSize -&amp;gt; Dimensions[#][[1]]] &amp;amp;&#xD;
         ]&#xD;
&#xD;
(* Computing time: 0.187943 s *)&#xD;
```&#xD;
&#xD;
![MandelbrotSetPlotOver(-2-1.2I,1+1.2I)][12]&#xD;
&#xD;
Clearly at this resolution scale, `MandelbrotSetPlot` is much faster than our neural-net function. But at a much larger resolution our function will eventually win.&#xD;
&#xD;
```&#xD;
myMandelbrotSetPlotTiming[resolution_Integer] := &#xD;
 Module[ {region = {-2 - 1.2 I, 1 + 1.2 I}, aspr, resol}&#xD;
       , region = region // ReIm // Transpose&#xD;
       ; aspr   = region.{-1, 1} // Reverse // Apply[Divide]&#xD;
       ; resol  = resolution {1, aspr} // Round&#xD;
       ; {resol, region} //&#xD;
            pipe[&#xD;
                  MapThread[Rescale[Range[#1] // N // Rescale, {0, 1}, #2] &amp;amp;]&#xD;
                , Tuples&#xD;
                , AssociationThread[{&amp;#034;cX&amp;#034;, &amp;#034;cY&amp;#034;}, #\[Transpose]] &amp;amp;&#xD;
                , AbsoluteTiming[mandelbrotF[#, WorkingPrecision -&amp;gt; &amp;#034;Real64&amp;#034;, TargetDevice -&amp;gt; &amp;#034;GPU&amp;#034;];][[1]] &amp;amp;&#xD;
                , {resolution, #} &amp;amp;&#xD;
                ]&#xD;
       ]&#xD;
&#xD;
myTimeTest = myMandelbrotSetPlotTiming /@ Range[101, 4001, 100];&#xD;
&#xD;
NonlinearModelFit[myTimeTest, a r^k, {a, k}, r][r] //&#xD;
  LogLogPlot[#, {r, 400, 5000}, PlotStyle -&amp;gt; Directive[Purple, AbsoluteThickness[2]], Frame -&amp;gt; True, FrameTicks -&amp;gt; All] &amp;amp; //&#xD;
 Show[ {&#xD;
         #&#xD;
       , ListLogLogPlot[myTimeTest, PlotMarkers -&amp;gt; Graphics[{FaceForm[White], EdgeForm[{Orange, AbsoluteThickness[1]}], Polygon[CirclePoints[4]]}, ImageSize -&amp;gt; 7], PlotRange -&amp;gt; All]&#xD;
       }&#xD;
     , FrameLabel -&amp;gt; {&amp;#034;ImageResolution&amp;#034;, &amp;#034;AbsoluteTiming&amp;#034;}&#xD;
     ] &amp;amp;&#xD;
```&#xD;
&#xD;
![time benchmark of NN based mandelbrot][13]&#xD;
&#xD;
Comparing with previous benchmark result of `MandelbrotSetPlot`, we can see our NN-based function has an advantage when the image resolution is large enough.&#xD;
&#xD;
![time bench comparison][14]&#xD;
&#xD;
---&#xD;
&#xD;
# Mandelbrot set on neural network -- Avoid overflow&#xD;
&#xD;
Careful readers will find that for larger iteration steps and/or a larger computing region, our naïvely implemented `mandelbrot` will lead to overflow. That is of course due to the $c$ values leading to divergency. One simple way to avoid this overflow is to constrain the nested $z$ to a bounded region at every iteration step.&#xD;
&#xD;
## The implementation&#xD;
&#xD;
### A constrained iteration core net&#xD;
&#xD;
The simplest way to constrain the nested $z$ is to clip it into a rectangle region.&#xD;
&#xD;
```&#xD;
iterNet = Module[{c = cX + cY I, z = x + y I},&#xD;
  z^2 + c // pipe[&#xD;
                   ReIm, ComplexExpand, Echo[#, &amp;#034;{Re[\!\(\*SuperscriptBox[\(z\), \(2\)]\)+c], Im[\!\(\*SuperscriptBox[\(z\), \(2\)]\)+c]}:&amp;#034;] &amp;amp;&#xD;
                 , Map@pipe[&#xD;
(* The constraint: -&amp;gt; *)     Block[{escR = 3}, escR Clip[#/escR]] &amp;amp;&#xD;
                           , Inactive[Function][{cX, cY, x, y}, #] &amp;amp;&#xD;
                           , Activate&#xD;
                           , ThreadingLayer&#xD;
                           ]&#xD;
                 , Inactive[NetGraph][#&#xD;
                                         , {&#xD;
                                                (NetPort /@ StringSplit[&amp;#034;cX,cY,x,y&amp;#034;, &amp;#034;,&amp;#034;]) -&amp;gt; # &amp;amp; /@ {1, 2}&#xD;
                                                , 1 -&amp;gt; NetPort[&amp;#034;x&amp;#034;], 2 -&amp;gt; NetPort[&amp;#034;y&amp;#034;]&#xD;
                                           }&#xD;
                                     ] &amp;amp;&#xD;
                 , Activate&#xD;
                 ]&#xD;
  ]&#xD;
```&#xD;
&#xD;
### The Mandelbrot net&#xD;
&#xD;
Re-evaluating the rest of the code leads to our simply constrained `mandelbrotCons` function.&#xD;
&#xD;
```&#xD;
nestcoreNet = NetGraph[&#xD;
                        {PartLayer[1], PartLayer[2], iterNet, zNet}&#xD;
                      , {&#xD;
                          (NetPort[#] -&amp;gt; NetPort[3, #]) &amp;amp; /@ StringSplit[&amp;#034;cX,cY&amp;#034;, &amp;#034;,&amp;#034;]&#xD;
                        , NetPort[&amp;#034;z&amp;#034;] -&amp;gt; {1, 2}&#xD;
                        , {{1, 2}, StringSplit[&amp;#034;x,y&amp;#034;, &amp;#034;,&amp;#034;]} // MapThread[(#1 -&amp;gt; NetPort[3, #2]) &amp;amp;]&#xD;
                        , {StringSplit[&amp;#034;x,y&amp;#034;, &amp;#034;,&amp;#034;], StringSplit[&amp;#034;1,2&amp;#034;, &amp;#034;,&amp;#034;]} // MapThread[(NetPort[3, #1] -&amp;gt; NetPort[4, #2]) &amp;amp;]&#xD;
                        }&#xD;
                      ]&#xD;
```&#xD;
```&#xD;
ClearAll[mandelbrotCons]&#xD;
mandelbrotCons[iterNum_Integer?Positive] :=&#xD;
     NetGraph[{&#xD;
                zNet&#xD;
              , ElementwiseLayer[0 # &amp;amp;]&#xD;
              , NetNestPartialOperator[nestcoreNet, StringSplit[&amp;#034;cX,cY&amp;#034;, &amp;#034;,&amp;#034;], &amp;#034;z&amp;#034;, iterNum]&#xD;
              },&#xD;
              {&#xD;
                {NetPort[&amp;#034;cX&amp;#034;], NetPort[&amp;#034;cY&amp;#034;]} -&amp;gt; 1 -&amp;gt; 2&#xD;
              , {2, NetPort[&amp;#034;cX&amp;#034;], NetPort[&amp;#034;cY&amp;#034;]} -&amp;gt; 3&#xD;
              }&#xD;
             ]&#xD;
```&#xD;
&#xD;
## Results&#xD;
&#xD;
Now we can go for much larger iteration steps on a larger region.&#xD;
&#xD;
```&#xD;
mandelbrotConsF = mandelbrotCons[200];&#xD;
```&#xD;
```&#xD;
result =&#xD;
  Module[{region = {-3 - 2 I, 1 + 2 I}, resol = 1001, aspr},&#xD;
         region = region // ReIm // Transpose&#xD;
         ; aspr = region.{-1, 1} // Reverse // Apply[Divide]&#xD;
         ; resol = resol {1, aspr} // Round&#xD;
         ; {resol, region} //&#xD;
             pipe[&#xD;
                   MapThread[Rescale[Range[#1] // N // Rescale, {0, 1}, #2] &amp;amp;]&#xD;
                   , Tuples&#xD;
                   , AssociationThread[{&amp;#034;cX&amp;#034;, &amp;#034;cY&amp;#034;}, #\[Transpose]] &amp;amp;&#xD;
                   , AbsoluteTiming[mandelbrotConsF[#, WorkingPrecision -&amp;gt; &amp;#034;Real64&amp;#034;, TargetDevice -&amp;gt; &amp;#034;GPU&amp;#034;]] &amp;amp;&#xD;
                   , pipe[&#xD;
                            branch[pipe[First, Quantity[#, &amp;#034;Seconds&amp;#034;] &amp;amp;, Echo[#, &amp;#034;Computing time on NN:&amp;#034;] &amp;amp;], Last]&#xD;
                            , Last]&#xD;
                   , Developer`ToPackedArray&#xD;
                   , ArrayReshape[#, {2, Sequence @@ resol}] &amp;amp;&#xD;
                   , {1, I}.# &amp;amp;&#xD;
                   , Transpose, Reverse&#xD;
                 ]&#xD;
        ];&#xD;
&#xD;
(* Computing time on NN: 6.29684 s *)&#xD;
```&#xD;
```&#xD;
result // Dimensions&#xD;
(* {1001, 1001} *)&#xD;
```&#xD;
```&#xD;
result //&#xD;
   pipe[&#xD;
         branch[&#xD;
                 pipe[ Abs&#xD;
                     , pipe[&#xD;
                             branch[Flatten /* HistogramTransform, Dimensions /* Last]&#xD;
                           , Apply@Partition&#xD;
                           ]&#xD;
                     , Rescale, (1 - #)^5 &amp;amp;&#xD;
                     ]&#xD;
               , pipe[Arg, Sin, Rescale]&#xD;
               ]&#xD;
       , Map @ pipe[&#xD;
                     Image[#, ImageSize -&amp;gt; Length[#]] &amp;amp;&#xD;
                   , Colorize[#, ColorFunction -&amp;gt; &amp;#034;DarkColorFractalGradient&amp;#034;] &amp;amp;&#xD;
                   ]&#xD;
       ]&#xD;
```&#xD;
&#xD;
![constrained result][15]&#xD;
&#xD;
Or thresholding at 2 to get the classical Mandelbrot set.&#xD;
&#xD;
```&#xD;
result // Abs // UnitStep[2 - #] &amp;amp; // Image&#xD;
```&#xD;
&#xD;
![classical Mandelbrot 200][16]&#xD;
&#xD;
### Zoom-in&#xD;
&#xD;
For zoomed-in regions, this clipped version gives interesting results.&#xD;
&#xD;
```&#xD;
result =&#xD;
  Module[{region = {-0.65 + 0.47 I, -0.4 + 0.72 I}, resol = 1001, aspr},&#xD;
         region = region // ReIm // Transpose&#xD;
         ; aspr = region.{-1, 1} // Reverse // Apply[Divide]&#xD;
         ; resol = resol {1, aspr} // Round&#xD;
         ; {resol, region} //&#xD;
             pipe[&#xD;
                   MapThread[Rescale[Range[#1] // N // Rescale, {0, 1}, #2] &amp;amp;]&#xD;
                   , Tuples&#xD;
                   , AssociationThread[{&amp;#034;cX&amp;#034;, &amp;#034;cY&amp;#034;}, #\[Transpose]] &amp;amp;&#xD;
                   , AbsoluteTiming[mandelbrotConsF[#, WorkingPrecision -&amp;gt; &amp;#034;Real64&amp;#034;, TargetDevice -&amp;gt; &amp;#034;GPU&amp;#034;]] &amp;amp;&#xD;
                   , pipe[&#xD;
                            branch[pipe[First, Quantity[#, &amp;#034;Seconds&amp;#034;] &amp;amp;, Echo[#, &amp;#034;Computing time on NN:&amp;#034;] &amp;amp;], Last]&#xD;
                            , Last]&#xD;
                   , Developer`ToPackedArray&#xD;
                   , ArrayReshape[#, {2, Sequence @@ resol}] &amp;amp;&#xD;
                   , {1, I}.# &amp;amp;&#xD;
                   , Transpose, Reverse&#xD;
                 ]&#xD;
        ];&#xD;
&#xD;
(* Computing time on NN: 6.06289 s *)&#xD;
```&#xD;
```&#xD;
result // pipe[&#xD;
                branch[&#xD;
                        pipe[ Abs&#xD;
                            , pipe[branch[Flatten /* HistogramTransform, Dimensions /* Last], Apply@Partition]&#xD;
                            , Rescale, (1 - #)^5 &amp;amp;, Sin[\[Pi]/2 #] &amp;amp;, Rescale&#xD;
                            ]&#xD;
                      , pipe[Arg, Sin[#/2] &amp;amp;, Rescale]&#xD;
                      ]&#xD;
              , Map@pipe[ Image[#, ImageSize -&amp;gt; Round[Length[#]/2]] &amp;amp;&#xD;
                        , Colorize[#, ColorFunction -&amp;gt; &amp;#034;StarryNightColors&amp;#034;] &amp;amp;&#xD;
                        ]&#xD;
              ]&#xD;
```&#xD;
&#xD;
![zoom-inAt(-0.65+0.47I,-0.4+0.72I)][17]&#xD;
&#xD;
### Complex map&#xD;
&#xD;
We can also stylize the result any way we want, say, showing the complex mapping like the [`ComplexPlot`](https://reference.wolfram.com/language/ref/ComplexPlot.html).&#xD;
&#xD;
Abs vs. Arg:&#xD;
&#xD;
```&#xD;
result // pipe[&#xD;
                branch[&#xD;
                        pipe[ Arg&#xD;
                            , branch[&#xD;
                                      pipe[Sin[#/2] &amp;amp;, Rescale]&#xD;
                                    , pipe[&#xD;
                                            Sin[50 #] &amp;amp;, ArcSin, Rescale, #^.5 &amp;amp;&#xD;
                                          ]&#xD;
                                    ]&#xD;
                            ]&#xD;
                      , pipe[&#xD;
                              Abs&#xD;
                            , Rescale, Log[10^-3 + #] &amp;amp;, Rescale&#xD;
                            , branch[&#xD;
                                      pipe[Sin[200 #] &amp;amp;, ArcSin, Rescale, #^.5 &amp;amp;]&#xD;
                                    , pipe[#^5 &amp;amp;, Rescale[#, {0, 1}, {1, .3}] &amp;amp;]&#xD;
                                    ]&#xD;
                            ]&#xD;
                      ]&#xD;
              , Apply@Function[{arg2, abs2}, {arg2[[1]], arg2[[2]] abs2[[1]], abs2[[2]]}]&#xD;
              , Image[#, ColorSpace -&amp;gt; &amp;#034;HSB&amp;#034;, Interleaving -&amp;gt; False] &amp;amp;&#xD;
              ]&#xD;
```&#xD;
&#xD;
![Complex map: Abs vs Arg][18]&#xD;
&#xD;
Or Re vs. Im:&#xD;
&#xD;
```&#xD;
result // pipe[&#xD;
                branch[&#xD;
                      pipe[&#xD;
                            ReIm, Transpose[#, {2, 3, 1}] &amp;amp;&#xD;
                          , Map@pipe[&#xD;
                                      Cos[100 2 \[Pi] #] &amp;amp;, Rescale, #^.2 &amp;amp;&#xD;
                                    ]&#xD;
                          ]&#xD;
                      , pipe[&#xD;
                              Abs&#xD;
                            , Rescale, Log[10^-3 + #] &amp;amp;, Rescale&#xD;
                            , branch[&#xD;
                                      pipe[Sin[\[Pi]/2 #] &amp;amp;, Rescale]&#xD;
                                    , pipe[#^5 &amp;amp;, Rescale[#, {0, 1}, {1, .5}] &amp;amp;]&#xD;
                                    ]&#xD;
                            ]&#xD;
                      ]&#xD;
              , Apply@Function[{reim, abs2}, {abs2[[1]], Times @@ reim, abs2[[2]]}]&#xD;
              , Image[#, ColorSpace -&amp;gt; &amp;#034;HSB&amp;#034;, Interleaving -&amp;gt; False] &amp;amp;&#xD;
              ]&#xD;
```&#xD;
&#xD;
![Complex map: Re vs Im][19]&#xD;
&#xD;
### A different region&#xD;
&#xD;
(The detailed code in this section is omitted in the post, but included in the attached notebook.)&#xD;
&#xD;
Computing over a different region (`-0.0452407411 + 0.9868162204352258 I + 2.7 10^-5 {-1 - I, 1 + I}`) and fiddling with color palettes from `ColorData[&amp;#034;ThemeGradients&amp;#034;]` gives us this wallpaper-like result (the [`ColorFunction`](https://reference.wolfram.com/language/ref/Colorize.html#777264821) used here is `&amp;#034;M10DefaultDensityGradient&amp;#034;`).&#xD;
&#xD;
![zoom-in 2][20]&#xD;
&#xD;
Also the corresponding complex map plots:&#xD;
&#xD;
![complex maps: Abs vs Arg &amp;amp; Re vs Im][21]&#xD;
&#xD;
---&#xD;
&#xD;
# References&#xD;
&#xD;
 - [Exploding the Dark Heart of Chaos](https://dhushara.com/DarkHeart/DarkHeart.htm)&#xD;
 &#xD;
 - [Wikipedia: External ray](https://en.wikipedia.org/wiki/External_ray)&#xD;
 &#xD;
 - [MathWorld: Mandelbrot Set](http://mathworld.wolfram.com/MandelbrotSet.html)&#xD;
 &#xD;
 - [Wikipedia: Mandelbrot set](https://en.wikipedia.org/wiki/Mandelbrot_set)&#xD;
&#xD;
 - [The Mandelbrot Set Browser](http://www.cuug.ab.ca/dewara/mandelbrot/Mandelbrowser.html)&#xD;
&#xD;
  [1]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Mandelbrot_wallpaper.png&amp;amp;userId=93201&#xD;
  [2]: https://community.wolfram.com//c/portal/getImageAttachment?filename=9_iteration_abs.png&amp;amp;userId=93201&#xD;
  [3]: https://community.wolfram.com//c/portal/getImageAttachment?filename=ReIm_Complex_map.png&amp;amp;userId=93201&#xD;
  [4]: https://community.wolfram.com//c/portal/getImageAttachment?filename=3D_mesh.png&amp;amp;userId=93201&#xD;
  [5]: https://community.wolfram.com//c/portal/getImageAttachment?filename=MandelbrotSetPlot.png&amp;amp;userId=93201&#xD;
  [6]: https://community.wolfram.com//c/portal/getImageAttachment?filename=time_bench_MandelbrotSetPlot.png&amp;amp;userId=93201&#xD;
  [7]: https://community.wolfram.com//c/portal/getImageAttachment?filename=iterNet.png&amp;amp;userId=93201&#xD;
  [8]: https://community.wolfram.com//c/portal/getImageAttachment?filename=iterNet_Nest.png&amp;amp;userId=93201&#xD;
  [9]: https://community.wolfram.com//c/portal/getImageAttachment?filename=NetNestPartialOperator_example.png&amp;amp;userId=93201&#xD;
  [10]: https://community.wolfram.com//c/portal/getImageAttachment?filename=nestcoreNet.png&amp;amp;userId=93201&#xD;
  [11]: https://community.wolfram.com//c/portal/getImageAttachment?filename=naive_result.png&amp;amp;userId=93201&#xD;
  [12]: https://community.wolfram.com//c/portal/getImageAttachment?filename=MandelbrotSetPlot2.png&amp;amp;userId=93201&#xD;
  [13]: https://community.wolfram.com//c/portal/getImageAttachment?filename=time_bench_NN.png&amp;amp;userId=93201&#xD;
  [14]: https://community.wolfram.com//c/portal/getImageAttachment?filename=time_bench_comparison.png&amp;amp;userId=93201&#xD;
  [15]: https://community.wolfram.com//c/portal/getImageAttachment?filename=constrained_result.png&amp;amp;userId=93201&#xD;
  [16]: https://community.wolfram.com//c/portal/getImageAttachment?filename=classical_Mandelbrot_200.png&amp;amp;userId=93201&#xD;
  [17]: https://community.wolfram.com//c/portal/getImageAttachment?filename=zoom_in_1.png&amp;amp;userId=93201&#xD;
  [18]: https://community.wolfram.com//c/portal/getImageAttachment?filename=AbsArg_Complex_map.png&amp;amp;userId=93201&#xD;
  [19]: https://community.wolfram.com//c/portal/getImageAttachment?filename=ReIm_Complex_map.png&amp;amp;userId=93201&#xD;
  [20]: https://community.wolfram.com//c/portal/getImageAttachment?filename=Mandelbrot_wallpaper.png&amp;amp;userId=93201&#xD;
  [21]: https://community.wolfram.com//c/portal/getImageAttachment?filename=complex_maps_2.png&amp;amp;userId=93201</description>
    <dc:creator>Silvia Hao</dc:creator>
    <dc:date>2019-12-19T07:59:59Z</dc:date>
  </item>
  <item rdf:about="https://community.wolfram.com/groups/-/m/t/143526">
    <title>How do I find x in a polynomial when x is approximate?</title>
    <link>https://community.wolfram.com/groups/-/m/t/143526</link>
    <description>I have difficulty programming to find x in a polynomial. I try NSolve to set the equation to zero and solve for x.
If N = 85, x= 5, and y = 17

I have an equation:[mcode]y = sqrt((N * y  x^2)/x)[/mcode]as an approximation of the larger Prime product (or any possible product)

My equation as it stands does not find x. I know there is a margin of error in the equation. This error can be subtracted to get a closer approximation. For example:
In the following equations: y = 17.2941176471 = 16.8522995464 This is the answer when subtracting the 2 equations below to find x knowing only N. Look at the Yellow.

So as the equations approach 0 (plus the margin of error). So since it is an approximation I need to find those values that are less than 1 and greater than 0. But 16.9082 is the value of the equation and not the value of x which should be found.
I need help programming this. So if anyone can help it would be much appreciated.
[mcode]y = sqrt[(((85/x) * 85 - x^2)/ x) ]= ((85^2/x) + x^2)/ 85

p = ((((85^2/x) + x^2)/ 85 ) ^2)- (((85/x) * 85 - x^2)/ x )^2 - 0.4418181007  ;

sol = NSolve[p?0, x] 

{{x?-86.8953},{x?82.8717},{x?23.3122},{x?-7.50642+19.0312 ?},{x?-7.50642-19.0312 ?},
{x?-10.592+14.3276 ?},{x?-10.592-14.3276 ?},{x?16.9082}}[/mcode][mcode]y = sqrt[(N * y - x^2) / x] 
y = sqrt[(7872197 * 3191 - 2467^2) / 2467][/mcode]
You can see this work at [url=http://www.3dbuzz.com/forum/threads/200441-New-One-Way-Function/page2]http://www.3dbuzz.com/forum/threads/200441-New-One-Way-Function/page2[/url]
Look at the last page first.
Also my website is [url=www.constructorscorner.net]www.constructorscorner.net[/url]</description>
    <dc:creator>Bobby Joe Snyder</dc:creator>
    <dc:date>2013-10-23T22:58:02Z</dc:date>
  </item>
</rdf:RDF>

