Recent Questions - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2020-08-14T23:56:39Z https://mathematica.stackexchange.com/feeds https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/228547 1 Given a plot of a network Graph[] how can the {x,y} screen coordinates be output? Tim https://mathematica.stackexchange.com/users/416 2020-08-14T22:20:52Z 2020-08-14T22:59:16Z <p>Is there a general way to get the screen or &quot;world&quot; coordinates for every vertex in the graphic output of something like this?</p> <pre><code>Table[Graph[Table[i \[UndirectedEdge] i + 1, {i, 20}], GraphLayout -&gt; l, PlotLabel -&gt; l], {l, {&quot;CircularEmbedding&quot;, &quot;SpiralEmbedding&quot;}}] </code></pre> <p>Trying to build an algorithm to generate novel layouts and want to use a large amount of other algorithms for training data.</p> https://mathematica.stackexchange.com/q/228546 0 With notebook's default context set to "Unique to each cell group", how do I make "Evaluate in Place" work in a text cell? Mark Mitchell https://mathematica.stackexchange.com/users/74221 2020-08-14T21:28:46Z 2020-08-14T23:26:07Z <p>With the notebook's default context set to &quot;Unique to each cell group&quot;, I have:</p> <pre><code>x=1 The value of x = x </code></pre> <p>where the second line is a text cell with an inline cell (created with Ctrl-9). When I select x in the inline cell and choose <code>Evaluation-&gt;Evaluate in Place</code>, the value does not update. When the notebook's default context is global, this works as expected. If I ask for the value of <code>x</code> in a subsequent cell (in the same cell group as the assignment and the text cell), the value is <code>1</code> as expected.</p> <p>How do I make <code>Evaluation-&gt;Evaluate in Place</code> work when the notebook's default context is set to &quot;Unique to Each Cell Group&quot;?</p> https://mathematica.stackexchange.com/q/228545 0 Mathematica Not Evaluating Small Input arow257 https://mathematica.stackexchange.com/users/69037 2020-08-14T21:14:11Z 2020-08-14T22:50:18Z <p>So I'm a bit confused. I asked Mathematica to evaluate</p> <pre><code>PolyLog[3, -4.900612445719819*^-15 + 8.488109744191103*^-15 I] </code></pre> <p>and it refused to do so</p> <p><a href="https://i.stack.imgur.com/3Qu0j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3Qu0j.png" alt="" /></a></p> <p>I assume it has something to do with the values being &quot;too small&quot;, since It seems to work fine for other values, e.g.</p> <p><a href="https://i.stack.imgur.com/ZA2z7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZA2z7.png" alt="enter image description here" /></a></p> <p>Does anyone know how to make Mathematica evaluate this input?</p> https://mathematica.stackexchange.com/q/228544 0 How can we speed up a matrix multiplication using ParallelTable and ParallelISum? HD2006 https://mathematica.stackexchange.com/users/26937 2020-08-14T20:53:02Z 2020-08-14T20:53:02Z <p>I do belive that Mathematica can work as fast as other packages, but it is really sensitive to the way we write the code. Here I would like to evaluate a trace resulted from a matrix multiplication at many points as follwos</p> <pre><code>KS[x_, y_,z_] := {{0, I Sin[x] + Sin[y], 13/4 - Cos[x] - Cos[y] - Cos[z] - I Sin[z], -1}, {-I Sin[x] + Sin[y], 0, -1, 13/4 - Cos[x] - Cos[y] - Cos[z] - I Sin[z]}, {13/4 - Cos[x] - Cos[y] - Cos[z] + I Sin[z], -1, 0, -I Sin[x] - Sin[y]}, {-1, 13/4 - Cos[x] - Cos[y] - Cos[z] + I Sin[z], I Sin[x] - Sin[y], 0}}; Oz[x_, y_,z_] := {{0, 0, 0, 1/2 (-Cos[z] - I Sin[z])}, {0, 0, 1/2 (Cos[z] + I Sin[z]), 0}, {0, 1/2 (Cos[z] - I Sin[z]), 0, 0}, {1/2 I (I Cos[z] + Sin[z]), 0, 0, 0}}; Ox[x_, y_,z_] := {{0, I Cos[x], Sin[x], 0}, {-I Cos[x], 0, 0, Sin[x]}, {Sin[x], 0, 0, -I Cos[x]}, {0, Sin[x], I Cos[x], 0}}; F2[x_, y_, z_, r_] := (Inverse[(r + I*0.01)*IdentityMatrix - KS[x, y, z]]); F1[x_, y_, z_, r_] := (Inverse[(r - I*0.01)*IdentityMatrix - KS[x, y, z]]); Myfun[x_, y_, z_, r_] := Re[Tr[(Ox[x, y, z].(F2[x, y, z, r] - F1[x, y, z, r]).Oz[x, y, z].(F2[x, y, z, r].F2[x, y, z, r] + F1[x, y, z, r].F1[x, y, z, r]))]]; </code></pre> <p>Then I used <code>ParallelSum</code> with <code>Table</code> to do the job, but it is very slow&gt; Is there any way to speed it up?</p> <pre><code>nr=5;nc=9; Table[ParallelSum[(nc/(2\[Pi]))^-3 1/nr Myfun[x,y,z,r],{r,-7.25,R,1/nr},{x,\[Pi]/nc,\[Pi],(2\[Pi])/nc}, {y,\[Pi]/nc,\[Pi],(2\[Pi])/nc},{z,\[Pi]/nc,\[Pi],(2\[Pi])/nc}],{R,-1,1,0.5}]//AbsoluteTiming {9.9159,{1.64289,-1.40237,-1.40319,-1.40314,0.10968}} </code></pre> <p>I want to do it with <code>nr=100</code> and <code>nc=200</code>.</p> https://mathematica.stackexchange.com/q/228543 1 Generalize WienerProcess Kenric https://mathematica.stackexchange.com/users/63334 2020-08-14T19:29:11Z 2020-08-14T19:29:11Z <p>Together the <strong>WhiteNoiseProcess</strong>, which includes the option of specifying a specific distribution for the noise, and the <strong>TransformProcess</strong>, which allows functions of processes, provide a great deal of flexibility in creating discrete-time processes.</p> <p>There does not appear to be a similar approach to creating a custom continuous-time process. For instance, it would be nice it the <strong>WienerProcess</strong> function included an option to specify a distribution other than the Gaussian.</p> <p>I see from other questions that the discrete-time processes can be converted into continuous time processes by using Interpolation; however, it's not clear to me how to do this conversion in a way that the resulting process can be use with <strong>RandomFunction</strong>. To be more specific, while a Interpolation can be used to specify a specific conversion given {t_min, t_max, dt} it's not clear how to define a general continuous time process that <strong>RandomFunction</strong> will recognize.</p> https://mathematica.stackexchange.com/q/228541 0 How do I change the LabelStyle for all graphics producing functions programmatically (only for the current session) Kvothe https://mathematica.stackexchange.com/users/45020 2020-08-14T19:09:14Z 2020-08-14T19:25:52Z <p>I want to change the default label style (or every Font appearing in graphics if easier) programmatically for the current session. Specifically I want to change the color to black (from the default grey).</p> <p>For a single plot this can be done by specifying <code>LabelStyle -&gt; Black</code>. One might hope that the same method that works for some other settings such as <code>ImageSize</code> also works for other options (see <a href="https://mathematica.stackexchange.com/a/228506/45020">https://mathematica.stackexchange.com/a/228506/45020</a>). However, the following does nothing:</p> <pre><code>SetOptions[EvaluationNotebook[], GraphicsBoxOptions -&gt; {&quot;LabelStyle&quot; -&gt; Black}] </code></pre> <p>The reason is probably the one explained in <a href="http://this%20answer" rel="nofollow noreferrer">https://mathematica.stackexchange.com/a/36770/45020</a>. I tried implementing the solution from there but I fail at changing the stylesheet appropriately (let alone doing it programmatically).</p> <p><a href="https://mathematica.stackexchange.com/a/36774/45020">The other solution to that question</a> is programmatical but for some reason it fails to change the FontColor. (It does work in all other ways.)</p> https://mathematica.stackexchange.com/q/228540 1 Precision lost on function estimation Javier J Navarro https://mathematica.stackexchange.com/users/67134 2020-08-14T18:33:27Z 2020-08-14T22:58:33Z <p>I'm trying to plot a function such as:</p> <pre><code>fwC[k1_, tau_, FE_, COH_, X_, t_] = 1 + (Exp[-k1 t] FE tau (-1 + Exp[k1 t] X (-1 + k1 tau) + Exp[t (k1 - 1/tau)] (1 + X - k1 X tau)))/(COH (-1 + k1 tau)) </code></pre> <p>When I try to plot the function with the values:</p> <pre><code>Plot[fwC[20.09, 227.3, 1000. 10^-8, 10^-9, 0.1, x],{x, 0, 40.}, PlotRange -&gt; All, Frame -&gt; True] </code></pre> <p>I get the plot:</p> <p><a href="https://i.stack.imgur.com/l3pxr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l3pxr.png" alt="enter image description here" /></a></p> <p>For values of x &gt; 36. I have the warning &quot;General::munfl: Exp[-803.6] is too small to represent as a normalized machine number; precision may be lost.&quot; But writting the equation in 'numerical format' I have:</p> <pre><code>fwC[20.09, 227.3, 1000. 10^-8, 10^-9, 0.1, x] = 1 + 497.869 Exp[-20.09 x] (-1 - 455.546 Exp[20.0856 x] + 456.546 Exp[20.09 x]) </code></pre> <p>Once simplified gives:</p> <pre><code>f(x)= 227301. - 497.869 Exp[-20.09 x] - 226802. Exp[-0.00439947 x] </code></pre> <p>Which can be plotted in all the range without any precision problem:</p> <pre><code>Plot[{227301. - 497.869 Exp[-20.09 x] - 226802.130 Exp[-0.00439947 x],fwC[20.09, 227.3, 1000. 10^-8, 10^-9, 0.1, x]}, {x, 0, 1000.}, PlotRange -&gt; All, Frame -&gt; True] </code></pre> <p><a href="https://i.stack.imgur.com/6wiBI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6wiBI.png" alt="enter image description here" /></a></p> <p>In orange is the function, in blue the numerical simplified expression.</p> <p>Any help to overcome this kind of ploblems?</p> <p>Best regards</p> https://mathematica.stackexchange.com/q/228539 0 I want help to complete my optimization code Delaram Nematollahi https://mathematica.stackexchange.com/users/49217 2020-08-14T18:10:46Z 2020-08-14T23:24:54Z <p>I have this Functional for energy which depends on the list of angles (angset in the code):</p> <pre><code> \[ScriptL]0 = 4; b[j_] := (Pi/2) ((j - 1)/(2 \[ScriptL]0 + 1) angset = Table[ b[j] , {j, 1, 2 \[ScriptL]0 + 2}]; M[\[ScriptL]_, p1_, p2_, pp1_, pp2_] := (integ = Conjugate[ SphericalHarmonicY[\[ScriptL], p1, t, p]] SphericalHarmonicY[\[ScriptL], p2, t, p] Conjugate[ SphericalHarmonicY[\[ScriptL], pp1, t, p]] SphericalHarmonicY[\[ScriptL], pp2, t, p] Sin[t] // Simplify; Integrate[integ, {t, 0, \[Pi]}, {p, 0, 2 \[Pi]}, Assumptions -&gt; IntegrateImproperDumpvar \[Element] Reals]) energy = Sum[(Cos[angset[[p1]]] Sin[angset[[pp1 - 1]]] - Sin[angset[[p1 - 1]]] Cos[angset[[pp1]]] + If[p1 == pp1, Sin[angset[[p1 - 1]]] Cos[angset[[p1]]], 0]) (Cos[angset[[p2]]] Sin[angset[[pp2 - 1]]] - Sin[angset[[p2 - 1]]] Cos[angset[[pp2]]] + If[p2 == pp2, Sin[angset[[p2 - 1]]] Cos[angset[[p2]]], 0]) M[\[ScriptL]0, p1, p2, pp1, pp2], {p1, 2, 2 \[ScriptL]0 + 2}, {p2, 2, 2 \[ScriptL]0 + 2}, {pp1, 2, p1}, {pp2, 2, p2}] // N; </code></pre> <p>I want to randomly choose an angle from the list(angset), change it a little bit and create a new list of angles to recalculate the energy and continue doing this until I find the minimum energy.I know that I need two loops, one for choosing a random angle and one for changing the chosen random angle, but I am not sure how to go about it.</p> <p>I have started by writing a piece of code like this, but I want some help to make it work or if anyone has better ideas:</p> <pre><code> s = 0.2; \[ScriptL]0 = 4; result = Table[ r = RandomReal[{-1, 1}]; ranchoice = RandomChoice[angset]; newj = Flatten[Position[angset, ranchoice]]; newchoice = ranchoice + s*r; newangset = angset /. ranchoice -&gt; newchoice; energy = Sum[(Cos[angset[[p1]]] Sin[angset[[pp1 - 1]]] - Sin[angset[[p1 - 1]]] Cos[angset[[pp1]]] + If[p1 == pp1, Sin[angset[[p1 - 1]]] Cos[angset[[p1]]], 0]) (Cos[angset[[p2]]] Sin[angset[[pp2 - 1]]] - Sin[angset[[p2 - 1]]] Cos[angset[[pp2]]] + If[p2 == pp2, Sin[angset[[p2 - 1]]] Cos[angset[[p2]]], 0]) M[\[ScriptL]0, p1, p2, pp1, pp2], {p1, 2, 2 \[ScriptL]0 + 2}, {p2, 2, 2 \[ScriptL]0 + 2}, {pp1, 2, p1}, {pp2, 2, p2}] // N; newenergy = Sum[(Cos[newangset[[p1]]] Sin[newangset[[pp1 - 1]]] - Sin[newangset[[p1 - 1]]] Cos[newangset[[pp1]]] + If[p1 == pp1, Sin[newangset[[p1 - 1]]] Cos[newangset[[p1]]], 0]) (Cos[newangset[[p2]]] Sin[newangset[[pp2 - 1]]] - Sin[newangset[[p2 - 1]]] Cos[newangset[[pp2]]] + If[p2 == pp2, Sin[newangset[[p2 - 1]]] Cos[newangset[[p2]]], 0]) M[\[ScriptL]0, p1, p2, pp1, pp2], {p1, 2, 2 \[ScriptL]0 + 2}, {p2, 2, 2 \[ScriptL]0 + 2}, {pp1, 2, p1}, {pp2, 2, p2}] // N; If[newenergy &lt; energy, {newenergy, newchoice, newj} , newchoice = ranchoice - s*r;], {ntrial, 1, 10}] </code></pre> <p>I appreciate it if someone can help me with writing this piece of code.</p> https://mathematica.stackexchange.com/q/228537 0 Automating script running with Python hal https://mathematica.stackexchange.com/users/59983 2020-08-14T17:53:34Z 2020-08-14T17:53:34Z <p>This question is short of a hybrid and should and shouldn't <em>simultaneously</em> be here, but never the less, here it is:</p> <p>Suppose I have a <code>run.m</code> file</p> <pre><code>Print[&quot;It's running&quot;] Exit[] </code></pre> <p>and I want to run it from the CLI via a python script. I tried it using the <code>subprocess</code> module and the following script</p> <pre><code>#!/usr/bin/env python3 import subprocess subprocess.run(['math', '-run', '\&quot;&lt;&lt;run.m\&quot;']) </code></pre> <p>but it doesn't run it. Any ideas how to make it work?</p> <p>Of course this is a toy example, with the ultimate goal of automating the running of multiple Mma scripts.</p> https://mathematica.stackexchange.com/q/228535 2 Non-valid modulus when using LinearSolve LightsOutTorus https://mathematica.stackexchange.com/users/74220 2020-08-14T16:56:21Z 2020-08-14T23:16:12Z <p>I have a system of linear equations I want to solve mod 4, and I happen to know the solution, but I get an error when trying to solve it using LinearSolve. I define the matrix <code>M</code> on line 31, define my known solution, <code>b</code> on line 32, and verify it on line 33. But trying to solve it using LinearSolve I get the error <code>Matrix is not valid modulo 4</code>. Here's the print of my inputs and outputs:</p> <p><a href="https://i.stack.imgur.com/OVBtb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OVBtb.png" alt="Here's a print of the inputs and the error I get" /></a>.</p> <p>Edit:</p> <p>Here's the matrix in question</p> <pre><code>M := {{1, 1, 1, 1, 0, 0, 1, 0, 0}, {1, 1, 1, 0, 1, 0, 0, 1, 0}, {1, 1, 1, 0, 0, 1, 0, 0, 1}, {1, 0, 0, 1, 1, 1, 1, 0, 0}, {0, 1, 0, 1, 1, 1, 0, 1, 0}, {0, 0, 1, 1, 1, 1, 0, 0, 1}, {1, 0, 0, 1, 0, 0, 1, 1, 1}, {0, 1, 0, 0, 1, 0, 1, 1, 1}, {0, 0, 1, 0, 0, 1, 1, 1, 1}} </code></pre> <p>and the solution</p> <p><code>b := {0, 1, 0, 1, 0, 1, 2, 3, 2}</code>.</p> https://mathematica.stackexchange.com/q/228528 -1 How to compute a list of cities within a given radius of another city? Veritas Lux https://mathematica.stackexchange.com/users/47198 2020-08-14T16:07:02Z 2020-08-14T23:11:16Z <p>I have hitherto found a solution to this problem.</p> <p>Designate a city in the continental USA as <code>cityCenter</code>.</p> <p>Make a table with all large cities in the USA. I could also just try for large cities.</p> <p>Of those cities in the list, the list includes data from the continental USA.</p> <p>Use a module to list all cities which match the following criteria; distance between <code>cityCenter</code> and that city is at most a fixed radius. If the distance is less than a fixed real number, add to final list.</p> <p>Example: From San Francisco, some cities as far as Sacramento appear but not for Florida.</p> <p>Any insights would be appreciated.</p> https://mathematica.stackexchange.com/q/228524 5 How to enclose a closed curve with another identical slightly bigger closed curve? acoustics https://mathematica.stackexchange.com/users/53981 2020-08-14T15:13:16Z 2020-08-14T19:59:22Z <p>I have a closed curve. I am trying to enclose this closed curve with another closed curve, which looks identical in the shape of the first closed curve, but slightly bigger. How to do this?</p> <pre><code>pts = {{-1, 0}, {-1, 1}, {0, 0}, {1, 1}, {1, 0}}; Graphics[{Thick, BSplineCurve[pts, SplineClosed -&gt; True]}] </code></pre> https://mathematica.stackexchange.com/q/228522 0 Animating the solution to the Insulated 2D Heat equation with inital condition in a rectangular region Mayur Matada https://mathematica.stackexchange.com/users/74219 2020-08-14T14:41:08Z 2020-08-14T23:25:18Z <p>I am very new to mathematica and I tried to give my best shot at animating the 2d heat equation with a given initial condition:</p> <pre><code>heqn = D[u[x, y, t], t] == Laplacian[u[x, y, t], {x, y}]; ic = u[x, y, 0] == x+y; bca = DirichletCondition[Derivative[u[x, 10, t], x] == 0, True]; bcb =DirichletCondition[Derivative[u[10, y, t], y] == 0, True]; bc = {bca, bcb} sol = NDSolveValue[{heqn, ic, bc}, u, {x, 0, 10}, {y, 0, 10}, {t, 0, 30}]; </code></pre> <p>And this is the error I am getting:</p> <pre><code>NDSolveValue::fembdnl: The dependent variable in Derivative[u,x]==0 in the boundary condition DirichletCondition[Derivative[u,x]==0,True] needs to be linear. NDSolveValue::fembdnl: The dependent variable in Derivative[u,x]==0 in the boundary condition DirichletCondition[Derivative[u,x]==0,True] needs to be linear. NDSolveValue::fembdnl: The dependent variable in Derivative[u,x]==0 in the boundary condition DirichletCondition[Derivative[u,x]==0,True] needs to be linear. General::stop: Further output of NDSolveValue::fembdnl will be suppressed during this calculation. NDSolveValue::fembdnl: The dependent variable in Derivative[u,x]==0 in the boundary condition DirichletCondition[Derivative[u,x]==0,True] needs to be linear. NDSolveValue::fembdnl: The dependent variable in Derivative[u,x]==0 in the boundary condition DirichletCondition[Derivative[u,x]==0,True] needs to be linear. </code></pre> <p>Please Help me and tell me where i went wrong.</p> https://mathematica.stackexchange.com/q/228521 0 How can I use ParallelTable with ParallelSum effectively? HD2006 https://mathematica.stackexchange.com/users/26937 2020-08-14T14:36:56Z 2020-08-14T17:13:05Z <p>I have this expression (as an example) as a function of <code>nc</code> and <code>nr</code> (real one is more nasty)</p> <pre><code>F[x_, y_, z_, r_] = (Sin[x] + Sin[y] - Sin[z] - Cos[z] + Cos[x] Sin[y] Cos[z])/ 1000; sumF[x_, y_, z_, r_, nc_, nr_] := ParallelSum[ 8 (nc/(2 \[Pi]))^-3 1/nr F[x, y, z, r], {r, -8, -1, 1/ nr}, {x, -\[Pi], \[Pi], (2 \[Pi])/nc}, {y, -\[Pi], \[Pi], ( 2 \[Pi])/nc}, {z, -\[Pi], \[Pi], (2 \[Pi])/nc}] </code></pre> <p>and I would like to evaluate it at fixed <code>nc</code> and different values of <code>nr</code> ,for simplicity, say <code>nc=10</code> and <code>nr</code> runs from <code>5</code> to <code>30</code> with step <code>5</code> (real code it runs to 1000 or more). So simply, I am using <code>Table</code> for that but my question is how can I <code>Parallelize</code> this process and is that even possible? I tried <code>ParallelTable</code> instead of <code>Table</code> but it is more time expensive?!</p> <pre><code>Table[sumF[x,y,z,r,10,nr]//N,{nr,5,30,5}]//AbsoluteTiming {9.81641,{1.72881,1.7048,1.6968,1.69279,1.69039,1.68879}} </code></pre> <p>and with <code>ParallelTable</code></p> <pre><code>ParallelTable[sumF[x,y,z,r,10,nr]//N,{nr,5,30,5}]//AbsoluteTiming {13.062,{1.72881,1.7048,1.6968,1.69279,1.69039,1.68879}} </code></pre> https://mathematica.stackexchange.com/q/228513 0 Solve can not solve the equation correctly in Reals kile https://mathematica.stackexchange.com/users/65814 2020-08-14T13:25:17Z 2020-08-14T22:55:11Z <p>Here is the error I found.</p> <pre><code>r = 3; Solve[Sqrt[(r^2 Cos[m Pi] - x)^2 + (r^2 Sin[m Pi])^2] == 10 &amp;&amp; x &gt; 0 &amp;&amp; 0 &lt;= m &lt;= 2, x, Reals] </code></pre> <p><code>{{x -&gt; ConditionalExpression[ 9 Cos[m \[Pi]] + Sqrt[100 - 81 Sin[m \[Pi]]^2], 0 &lt;= m &lt; 1/2 || 1/2 &lt; m &lt; 3/2 || 3/2 &lt; m &lt;= 2]}}</code></p> <p>Mathematica says <span class="math-container">$m \neq \frac {1} {2}$</span> and <span class="math-container">$m \neq \frac {3} {2}$</span></p> <p>But I beleieve it can be equal to these 2 numbers.</p> <ol> <li>When <span class="math-container">$r=3,m= \frac {1} {2}$</span>,</li> </ol> <p><span class="math-container">$x = \sqrt {19}$</span></p> <ol start="2"> <li>When <span class="math-container">$r=3,m= \frac {3} {2}$</span>,</li> </ol> <p><span class="math-container">$x = \sqrt {19}$</span></p> https://mathematica.stackexchange.com/q/228512 0 Difficulty with MatrixPlot Kurapika https://mathematica.stackexchange.com/users/73799 2020-08-14T13:00:04Z 2020-08-14T23:18:23Z <p>I can use matrixplot for plotting basic functions but I am having problems with matrices. If I try to plot <code>Z={{3 Cos[t], 2Sin[t]}, {-8 Cos[t], 5Sin[t]}}</code> for <code>-50&lt;=t&lt;=50</code> I get a strange narrow box and I am not sure if it's correct at all. I used the following plot commands:</p> <pre><code>MatrixPlot[Table[UnitStep[{3 Cos[t], 2 Sin[t]}] UnitStep[{-8 Cos[t],5 Sin[t]}], {t, -50, 50}], PlotTheme -&gt; &quot;Detailed&quot;] </code></pre> <p>Is this the correct way to matrix plot what I mentioned?</p> https://mathematica.stackexchange.com/q/228509 -1 A series of factors or an equation? Joao Alves Marrucho https://mathematica.stackexchange.com/users/74217 2020-08-14T12:42:05Z 2020-08-14T23:24:18Z <p>Is there anybody that can help me simplify the following ideas in an equation, a series of factors or whatever mathematical form is easier to later use and understand? They all have to be true. 🙏</p> <p>x = (z/2)</p> <p>x = ((z+y)/3)</p> <p>z - y = a</p> <p>y - x = a</p> <p>X ≠ 0</p> <p>The main idea is that the diference between x and y is the same as the one between y and z. And that 3x is always the same as z + y and 2x is the same as z. Does this have a solution? If not I have to at least make it work with</p> <p>3x &gt; z+y</p> <p>and</p> <p>2x &gt; z</p> <p>instead of the first two arguments... 📐🤔</p> https://mathematica.stackexchange.com/q/228505 1 Change default Imagesize for all graphics functions programmatically only for the current session Kvothe https://mathematica.stackexchange.com/users/45020 2020-08-14T11:03:54Z 2020-08-14T23:21:56Z <p>How do I change the default Imagesize for all functions producing graphics programmatically for the current session (only)?</p> <p>Something close to an answer is given in <a href="https://mathematica.stackexchange.com/a/15270/45020">https://mathematica.stackexchange.com/a/15270/45020</a> but it either only changes the output of one function (such as Plot) or the solution uses the Frontend Menu instead of code.</p> https://mathematica.stackexchange.com/q/228504 2 How can I use AnatomyPlot3D with DICOM images? Dean https://mathematica.stackexchange.com/users/9238 2020-08-14T10:32:24Z 2020-08-14T23:10:32Z <p>I recently discovered beautiful things that can be achieved with <a href="https://reference.wolfram.com/language/ref/AnatomyPlot3D.html" rel="nofollow noreferrer">AnatomyPlot3D</a>. How can I apply this function to DICOM images from my local machine? Thanks in anticipation of your suggestions.</p> https://mathematica.stackexchange.com/q/228501 0 Solving parametric function numerically for positive values Thanatopseustes https://mathematica.stackexchange.com/users/74201 2020-08-14T09:43:52Z 2020-08-14T23:22:30Z <p>So I have a function <code>f1[x,y]</code> that includes a parameter <code>c</code>. I would like to solve the corresponding <code>f1[x,y]==0</code> for positive x and y (depending on <code>c</code>), with the further restriction that <code>c&gt;=0</code>, but I do not know how to encode all of this properly.</p> <p>My try was:</p> <pre><code>Reduce[f[x,y]==0 &amp;&amp; x&gt;0 &amp;&amp; y&gt;0 &amp;&amp;c&gt;=0, {x,y}] </code></pre> <p>But it does not seem to work (it is stuck &quot;running&quot;), while playing around a little bit <code>NSolve[f[x,y]==0, {x,y}]/. -&gt; c=1</code>, or any positive <code>c</code> have many solutions, among which some for positive <code>x</code> and <code>y</code>. Conversely, also <code>NSolve[f[x,y]==0 &amp;&amp;x&gt;0 &amp;&amp; y&gt;0, {x,y}]/. -&gt; c=1</code> is stuck running. Am I doing something wrong?</p> <p>To completely reproduce the framework I am using I would have to add many useless stuff, so I've worked out a minimal reproduction of the problem I have using two functions:</p> <pre><code>f1[x_, y_] := (50 (2 p^6 (20 + y) - p^2 (-2 + x) x^3 (20 + 3 y) + p^4 x (3 x (-20 + y) + 2 (60 + y))))/((p^2 + x^2)^3 (20 + y)) f2[x_, y_] := (p^4 (20 + y)^2 + x^4 (20 + y)^2 + 2 p^2 x^2 (1400 - 1000 x + 40 y + y^2))/((p^2 + x^2)^2 (20 + y)^2) NSolve[f1[x, y] == 0 &amp;&amp; f2[x, y] == 0, {x, y}] /. p -&gt; 4 </code></pre> <p>Where the NSolve gives as output:</p> <pre><code>{{x -&gt; 1.01264, y -&gt; -18.804}, {x -&gt; 5.21585, y -&gt; 24.3412}, {x -&gt; 6.26257, y -&gt; -66.5406}, {x -&gt; 179.176, y -&gt; -7.27542}, {x -&gt; -4.13331 - 0.549203 I, y -&gt; -22.4456 + 51.1497 I}, {x -&gt; -4.13331 + 0.549203 I, y -&gt; -22.4456 - 51.1497 I}, {x -&gt; -0.112599 - 2.93525 I, y -&gt; 91.3789 + 57.5289 I}, {x -&gt; -0.112599 + 2.93525 I, y -&gt; 91.3789 - 57.5289 I}, {x -&gt; 0.412582 - 2.45391 I, y -&gt; -55.0916 - 58.626 I}, {x -&gt; 0.412582 + 2.45391 I, y -&gt; -55.0916 + 58.626 I}} </code></pre> <p>Where the second one is clearly positive. However, <code>NSolve[f1[x, y] == 0 &amp;&amp; f2[x, y] == 0 &amp;&amp; x &gt; 0 &amp;&amp; y &gt; 0, {x, y}] /. p -&gt; 4</code> does not find it and remains stuck. At the same time, <code>Reduce</code> finds roots in the unbounded case and not in the bounded one.</p> https://mathematica.stackexchange.com/q/228500 0 Result of Integration over ImplicitPlot not as expected pigeon https://mathematica.stackexchange.com/users/27212 2020-08-14T09:43:26Z 2020-08-14T23:11:23Z <p>I am trying to Integrate the area mentioned below using ImplicitRegion function, following <a href="https://www.wolfram.com/mathematica/new-in-10/basic-and-formula-regions/integrate-over-regions.html" rel="nofollow noreferrer">this</a> resource. This method worked in many other scenario. The plot was accurate, but the integration returned 1/10 which is not true as is verified by the traditional integration. I have tried integration over <span class="math-container">$-1\leq y\leq 0$</span> and <span class="math-container">$0\leq y\leq 1$</span> separately and also using Surd[x,3]^2 but things got much weirder. Can any one give a hint how I can improve or correct this?</p> <p><span class="math-container">$\pmb{\text{reg}=\text{ImplicitRegion}\left[y\leq x\leq y^{\frac{2}{3}},\{x,\{y,-1,1\}\}\right]}$</span></p> <p><span class="math-container">$\text{ImplicitRegion}\left[y\leq x\leq y^{2/3}\&amp;\&amp;-1\leq y\leq 1,\{x,y\}\right]$</span></p> <p><span class="math-container">$\pmb{\text{RegionPlot}[\text{reg}]}$</span> <a href="https://i.stack.imgur.com/cbyuf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cbyuf.jpg" alt="enter image description here" /></a></p> <p><span class="math-container">$\pmb{\text{Integrate}[1,y\in \text{reg}]}$</span></p> <p><span class="math-container">$\frac{1}{10}$</span></p> <p><span class="math-container">$\pmb{\int_{-1}^1 \left(y^{\frac{2}{3}}-y\right) \, dy}$</span></p> <p><span class="math-container">$\frac{3}{5} \left(1+(-1)^{2/3}\right)$</span></p> https://mathematica.stackexchange.com/q/228499 1 How to find the shortest distance between two regions? Montevideo https://mathematica.stackexchange.com/users/42417 2020-08-14T08:25:30Z 2020-08-14T23:11:37Z <p>I need to find the shortest distance between the two regions and the two points of the shortest distance, but the following code cannot achieve this requirement:</p> <pre><code>reg1 = ImplicitRegion[ x^2 + y^2 - 2 z^2 == 0 &amp;&amp; x + y + 3 z == 5, {x, y, z}] reg2 = ImplicitRegion[z == 0, {x, y, z}] RegionNearest[reg1, reg2] </code></pre> <p>What can I do to find the shortest distance between two regions?</p> https://mathematica.stackexchange.com/q/228493 1 Array function and slot Max https://mathematica.stackexchange.com/users/74141 2020-08-14T06:20:11Z 2020-08-14T23:12:10Z <p>I am trying to make an Array depending on a function, and I saw that <code>Slot</code>is useful for my situation. There are examples described in <a href="https://reference.wolfram.com/language/ref/Array.html?view=all" rel="nofollow noreferrer">https://reference.wolfram.com/language/ref/Array.html?view=all</a> that I'm trying to mimic, but in a more complicated situation.</p> <p>So, I wrote the following:</p> <p><code>Array[g[Slot / 10 + I*Slot/10, Slot*10], {10, 10, 10}]</code></p> <p>but instead of actually evaluating the code, it just leaves the Slots unevaluated and just literally prints things like <code>10 Slot [1, 1, 1]</code>. This even happens with a very simple function, for instance:</p> <p><code>g[z_, n_] := n</code></p> <p>How can I actually get Mathematica to actually evaluate the slots?</p> https://mathematica.stackexchange.com/q/228491 1 Round-off error Slash020 https://mathematica.stackexchange.com/users/74209 2020-08-14T06:08:54Z 2020-08-14T23:23:45Z <p>Assuming <span class="math-container">$0&lt;q&lt;1$</span>. I built these two functions</p> <pre><code>A[k_,q_]:=Sum[PDF[BinomialDistribution[i, q], k]*PDF[ZipfDistribution[n], i], {i, k, Infinity}] </code></pre> <p>and</p> <pre><code>B[k_,q_]:=Piecewise[{ {(1/Zeta[n + 1])*PolyLog[n + 1, 1 - q], k == 0}, {(1/(Zeta[n + 1]*k!))*(q/(1 - q))^k*Sum[CoefficientList[Product[x - j, {j, 1, k - 1}],x][[-i]]* PolyLog[n + i - k, 1 - q], {i, 1, k}], k &gt; 0}}] </code></pre> <p>Functions A and B are mathematically equivalent for <span class="math-container">$k\geq1$</span>. (Function B is faster than function A.)</p> <p>When I compute <span class="math-container">$A[25,0.6]$</span> and <span class="math-container">$B[25,0.6]$</span> with <span class="math-container">$n=3$</span>, I start to get a little difference between the results <span class="math-container">$(5.61124*10^{-7},5.61132*10^{-7})$</span>. So, the question is, why is this difference? Does anyone know how to avoid this round-off problem?</p> https://mathematica.stackexchange.com/q/228480 0 Can you make a graph without storing values in a list first? D'Angelo https://mathematica.stackexchange.com/users/74202 2020-08-13T20:58:34Z 2020-08-14T23:20:22Z <p>For example if I had:</p> <pre><code>maxsize = 1000000; lis1 = {}; For[i = 1, i &lt;= maxsize, i++, lis1 = Append[lis1, i]] ListLinePlot[lis1] </code></pre> <p>In the current process a number is stored to <code>lis1</code> for each iteration and after the loop has ran 1 million times, a graph is then created. However, as more and more values are being stored, the process seems to slow down. So there are two questions I have:</p> <ol> <li><p>Is there a limit to the size of a list you can have in Mathematica? Is 1000000 entries in a list too many?</p> </li> <li><p>Assuming list size is not an issue, is there any way to directly just plot a value obtained from the loop without having to store it first? So in this example, instead of obtaining:</p> <p>lis1={1,2,3,4....1000000}</p> </li> </ol> <p>Is it possible to just take the integer given by each iteration of the loop and plot it to a graph without storing that value in a list beforehand?</p> <p>I know there may be other ways to make the graph which this specific loop shows, however I'm working on a a bit of code which happens to use a <code>For</code> loop in the same manner as the example above so any work arounds here in relation to that would be greatly appreciated.</p> https://mathematica.stackexchange.com/q/228464 9 How can I program the last digits of Fibonacci numbers? Allam A. https://mathematica.stackexchange.com/users/73137 2020-08-13T17:11:23Z 2020-08-14T23:09:41Z <p>Is there a way to compute the last digits of an arbitrarily large Fibonacci number?</p> <p>For the <span class="math-container">$10^n$</span>th Fibonacci number, we can just find the <span class="math-container">$2^n$</span>-th Fibonacci number (if that isn't too large) <span class="math-container">$\bmod n$</span>, and then use the <a href="https://en.wikipedia.org/wiki/Chinese_remainder_theorem" rel="nofollow noreferrer">Chinese remainder theorem</a>, since we know it is a multiple of <span class="math-container">$5^n$</span> (the <a href="https://en.wikipedia.org/wiki/Pisano_period" rel="nofollow noreferrer">Pisano period</a> is <span class="math-container">$4\cdot5^n$</span> which divides <span class="math-container">$10^n$</span>) to find the last <span class="math-container">$n$</span> digits.</p> <p>However, is there a way to find the last digits of the <span class="math-container">$n$</span>-th Fibonacci number efficiently if <span class="math-container">$n$</span> is not a power of <span class="math-container">$10$</span>?</p> <p>A way to program this would probably require a way to reference the last two intermediate values and add them together, and then taking the result <span class="math-container">$\bmod 10^d$</span>. Taking the value <span class="math-container">$\bmod 3\times10^d$</span> would be preferred because this allows the calculation to be iterated.</p> https://mathematica.stackexchange.com/q/228443 0 Load binary .mx files from list of paths? [duplicate] Kagaratsch https://mathematica.stackexchange.com/users/5517 2020-08-13T11:39:13Z 2020-08-14T23:19:00Z <p>I have several .mx files containing data saved to disk via <code>DumpSave</code>. I load a list of these files in my folder as</p> <pre><code>SetDirectory[NotebookDirectory[]]; files = FileNames[All, &quot;.\\data&quot;, Infinity]; </code></pre> <p>Now I was trying to load them via</p> <pre><code>&lt;&lt; files[] </code></pre> <p>or</p> <pre><code>&lt;&lt; ToExpression[files[]] </code></pre> <p>or even</p> <pre><code>&lt;&lt; Evaluate[ToExpression[files[]]] </code></pre> <p>none of which have worked. How can I load an .mx file using a string of its path?</p> https://mathematica.stackexchange.com/q/216479 0 Find the Minimum and Maximun of ListDensityPlot in Mathematica BumbaS https://mathematica.stackexchange.com/users/70319 2020-03-17T19:20:28Z 2020-08-14T20:03:25Z <p>I have a set of data points, lets say {x_i,y_i,A_i}. I want to find the Minimum and Maximum value of A_i from a ListDensityPlot in Mathematica. Along with the corresponding x_i &amp; y_i values.</p> https://mathematica.stackexchange.com/q/206422 0 An empty list is generating when I tried to find the roots of transcendental equation using NSOLVE function acoustics https://mathematica.stackexchange.com/users/53981 2019-09-18T13:07:29Z 2020-08-14T17:07:45Z <p>I have an equation P which is dependent on ω and γ, and I am trying to find the roots of ω for different value of γ. I have written a small module to carry out this task, but the output of the module is showing empty.</p> <pre><code> Y = 2*^11; ρ = 7850; aa = 0.1*0.1; Iyy = 0.1^4/12; sd1 = Subdivide[0.001, 0.5, 300]; sd2 = Subdivide[0.55, 2, 300]; sd3 = Subdivide[2.2, 5, 50]; sd = Flatten[{sd1, sd2}]; L1=4; lbar = L1*sd; P = 1/γ^4 aa^2 (Iyy^2 Y^6 (17.033 aa^2 + 121.171 aa Iyy γ + 56.7964 Iyy^2 γ^2) + Iyy Y^5 (-1.01106 aa^3 + aa^2 Iyy (-46.8109 - 15.3405 γ) γ + aa Iyy^2 (-160.727 - 64.3873 γ) γ^2 - 9.20748 Iyy^3 γ^4) ρ ω^2 + Y^4 (0.0117278 aa^4 + aa^3 Iyy (2.06068 + 0.910598 γ) γ + 0.373165 Iyy^4 γ^6 + aa Iyy^3 γ^4 (26.0561 + 6.63437 γ) + aa^2 Iyy^2 γ^2 (30.4847 + γ (24.8741 + 4.07576 γ))) ρ^2 ω^4 + aa Y^3 γ (aa^3 (-0.0154297 - 0.0105624 γ) + Iyy^3 (-1.05601 - 0.179254 γ) γ^5 + aa Iyy^2 γ^3 (-4.942 + (-2.56299 - 0.279973 γ) γ) + aa^2 Iyy γ (-0.960215 + (-1.09499 - 0.241934 γ) γ)) ρ^3 ω^6 + aa^2 Y^2 γ^2 (aa^2 (0.00488883 + (0.00819891 + 0.0028063 γ) γ) + Iyy^2 γ^4 (0.200292 + (0.0692493 + 0.00567345 γ) γ) + aa Iyy γ^2 (0.155664 + (0.112826 + 0.016619 γ) γ)) ρ^4 ω^8 + aa^3 Y γ^4 (Iyy γ^2 (-0.00630883 + (-0.00304845 - 0.000336771 γ) γ) + aa (-0.000792547 + (-0.000844803 - 0.000192771 γ) γ)) ρ^5 ω^10 + aa^4 γ^6 (0.0000321207 + (0.0000228257 + 3.90636*10^-6 γ) γ) ρ^6 ω^12); sd1 = Subdivide[0.001, 0.5, 300]; sd2 = Subdivide[0.55, 2, 300]; sd3 = Subdivide[2.2, 5, 50]; sd = Flatten[{sd1, sd2, sd3}]; lbar = L1*sd; sol[i_] := Module[{root}, P = P /. γ -&gt; lbar[[i]]; s1=NSolve[P == 0 &amp;&amp; 0 &lt; ω &lt; 2000]; s2 = Flatten[ω /. s1]; s3 = Surd[(ρ*aa*s2^2*L1^4)/(Y*Iyy), 4]; s4 = s3/(2 π); root = s4; Return[root]]; nonbeta = Table[sol[i], {i, 1, Length[lbar]}]; nonbeta1 = nonbeta[[All, 1]] </code></pre> https://mathematica.stackexchange.com/q/125303 6 How to create and export a procedural planet texture with normal map Cham https://mathematica.stackexchange.com/users/6260 2016-09-01T14:02:58Z 2020-08-14T22:57:57Z <p>I would like to generate some earth-like/mars-like/giant-gas-like planets/moon/asteroid textures with <em>normal map</em> and <em>specular map</em> as 4k PNG files (4096 X 2048 pixels), to be mapped on a sphere with some 3D software.</p> <p>I really know nothing about generating textures using <strong><em>Mathematica</em></strong>, so I'm starting from scratch here, and need help to write a full code to do this.</p> <p>The exported textures need to look realistic, with random mountains/valleys, craters, turbulence in the gas-giant, etc. The files need to be of resolution 4096 X 2048 pixels (or better), and have the standard mapping on a sphere (I think this is the <em>Mercator projection</em>, but I'm not sure).</p> <p>How to start this project with Mathematica ? Is this too ambitious to be done with Mathematica ?</p> <p>(I suspect that the generation process may be too slow with Mathematica, at that resolution, and it may be better to learn to use another specific software to generate planet textures)</p> <p>I'm thinking about textures a bit like this one (this is just an example) :</p> <p><a href="http://pics-about-space.com/planet-mercury-texture?p=2#img8875464233725793026">http://pics-about-space.com/planet-mercury-texture?p=2#img8875464233725793026</a></p> <hr> <p><strong>EDIT 1 :</strong></p> <p>If possible, codes should be compatible with older versions of <strong><em>Mathematica</em></strong>. Personaly, I'm still using version 7.0. But the questions above are applying to all versions. Please, if you post some code, specify to which version it is applying.</p>