Recent Questions - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2022-05-25T01:22:41Z https://mathematica.stackexchange.com/feeds https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/268670 0 Finding the periodicity (or wavelength) in approximately periodic data EGME https://mathematica.stackexchange.com/users/53849 2022-05-24T20:01:58Z 2022-05-24T21:13:53Z <p>I have data that looks as in the picture. Is there a function in Mathematica that allows me to find an approximate or average period or wavelength? I know beforehand that the data will always look like this, with some random wiggling. If there is no function that does this, how best to do it in Mathematica? Thanks in advance</p> <p><a href="https://i.stack.imgur.com/Svyxt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Svyxt.png" alt="enter image description here" /></a></p> https://mathematica.stackexchange.com/q/268669 1 How to use PlusMinus properly? user824530 https://mathematica.stackexchange.com/users/75136 2022-05-24T19:31:59Z 2022-05-24T21:43:16Z <p>As an easy exercise, I would like to define a function</p> <p><span class="math-container">$$f(x)=\pm x$$</span></p> <p>and be able to ListPlot the function for some discrete values.</p> <p>Here is what I tried</p> <pre><code>F[x_] := PlusMinus[x]; Table[F[x], {x, 1, 4}] </code></pre> <p>This gives me output</p> <pre><code>{\[PlusMinus]1, \[PlusMinus]2, \[PlusMinus]3, \[PlusMinus]4} </code></pre> <p>This is exactly what I want. But now I want to listplot it using</p> <pre><code>ListPlot[Table[F[x], {x, 1, 4}]] </code></pre> <p>But this does not give me output.</p> <p>So, I guess my question is how to convert the output of <code>PlusMinus</code> which is <span class="math-container">$\pm2$</span> to an array <span class="math-container">$\{-2,2\}$</span> so that I can do other operations on it.</p> https://mathematica.stackexchange.com/q/268668 1 Definite Integral of Probability Distributions user2757771 https://mathematica.stackexchange.com/users/55621 2022-05-24T19:03:22Z 2022-05-24T21:24:27Z <p>Suppose at each value of <span class="math-container">$x$</span> I define a normal distribution</p> <pre><code>dist[x_] := NormalDistribution[Sin[4 x], Cos[10 x]^2] </code></pre> <p>Now I want to find the distribution</p> <p><span class="math-container">$$\mathcal{D} = \int_{-1}^1 \text{dist}(x)\ dx$$</span></p> <p>This is essentially what <code>TransformedDistribution</code> is meant for but it's usually for simple combinations of distributions (e.g <code>TransformedDistribution[ x + y, {x \[Distributed] NormalDistribution[], y \[Distributed] NormalDistribution[]}]</code>) not integrals over a continuous set of disributions.</p> <p>Of course since <span class="math-container">$\text{dist}(x)$</span> is always normal I know that any sum of them is also normal which allows me to compute <span class="math-container">$\mathcal{D}$</span> exactly, but I wondering if theres some way to get Mathemtatica to output the exact result that uses all the power of <code>TransformedDistribution</code>.</p> <p>Thanks</p> <p>Exact solution should be</p> <pre><code>NormalDistribution[Integrate[Sin[4 x], {x, -1, 1}], Sqrt[Integrate[Cos[10 x]^4, {x, -1, 1}]]] </code></pre> <p><span class="math-container">$$\text{NormalDistribution}\left[0,\frac{1}{4} \sqrt{\frac{1}{10} (120+8 \sin (20)+\sin (40))}\right]$$</span></p> https://mathematica.stackexchange.com/q/268666 0 Useless and incorrect result of AsymptoticIntegrate user64494 https://mathematica.stackexchange.com/users/7152 2022-05-24T17:31:42Z 2022-05-24T17:31:42Z <p>In version 13 on Windows 10 I try to find asymptotic of the integral used in potential theory</p> <pre><code>as = AsymptoticIntegrate[ 1/(1 - 2*r*Cos[t] + r^2)^(n/2), {t, -Pi, Pi}, {r, 1, 1}, Assumptions -&gt; n &gt; 1 &amp;&amp; n \[Element] Integers &amp;&amp; r &gt; 0 &amp;&amp; r &lt; 1, GenerateConditions -&gt; True] // Simplify </code></pre> <blockquote> <p><code>\[Pi]^(3/2) (((-1)^n (-1 + r)^(1 - n))/( Gamma[3/2 - n/2] Gamma[n/2]) + (2^-n (2 + n - n r))/( Gamma[1 - n/2] Gamma[(1 + n)/2])) Sec[(n \[Pi])/2]</code></p> </blockquote> <p>However, the above asymptotic is useless and incorrect in view of</p> <pre><code>as /. {r -&gt; 0.9, n -&gt; 5} </code></pre> <blockquote> <p><code>ComplexInfinity</code></p> </blockquote> <p>and</p> <pre><code>Limit[(as /. r -&gt; 9/10), n -&gt; 5] </code></pre> <blockquote> <p><code>Indeterminate</code></p> </blockquote> <p>Does there exist a workaround?</p> https://mathematica.stackexchange.com/q/268663 0 How to mimic Expand with Thread? vtfs271232 https://mathematica.stackexchange.com/users/42141 2022-05-24T15:31:19Z 2022-05-24T15:31:19Z <p>I want to mimic <code>Expand[(a + b) (c + d)]</code> with <code>Thread</code>.</p> <p>My attempt below does not provide the correct result:</p> <pre><code>Thread[Times[a + b, c + d], Plus] </code></pre> <p>What is the correct way?</p> https://mathematica.stackexchange.com/q/268661 1 Looking for an appropriate method of NDSolve for dynamical system Artem Alexandrov https://mathematica.stackexchange.com/users/49992 2022-05-24T15:14:36Z 2022-05-24T15:44:42Z <p>I am dealing with the numerical solutions of a variety of dynamical systems with integrals of motion.</p> <p>As the example, let me consider the Kuramoto model, which equations of motion are</p> <pre><code>KuramotoEquations = Table[D[f[i][t], t] == g/M* Sum[Sin[f[j][t] - f[i][t]], {j,1, M}], {i, 1, M}]; </code></pre> <p>where <code>M</code> is the number of oscillators, <code>g</code> is the positve constant and <code>f[i]</code> is the phase of oscillator. This model has a set of motion integrals (it is the rigorous fact), that is tightly related to the Mobius equation. I try to probe these integrals of motion numerically.</p> <p>The Mobius transformation preserves the also-called <em>cross-ratio</em>. The cross ratio is defined as follows,</p> <pre><code>crossratio[f1_, f2_, f3_, f4_] := (Exp[I*f1]-Exp[I*f3])/(Exp[I*f1]-Exp[I*f4])*(Exp[I*f2] - - Exp[I*f4])/(Exp[I*f2] - Exp[I*f3]); </code></pre> <p>Due to existence of the mentioned motion integrals, the whole dynamics of model can be described as the Mobius transformation that acts on the initial conditions, which I can choose randomly from the given interval,</p> <pre><code>KuramotoInitials = Table[f[i] == RandomReal[{0, 2*Pi}], {i, 1, M}]; </code></pre> <p>In order to check that the cross-ratio is conserved, I compute it at moment <code>t=0</code> for my initial conditions,</p> <pre><code>KuramotoTestCrossRatio = crossratio[KuramotoInitialPhases[], KuramotoInitialPhases[], KuramotoInitialPhases[], KuramotoInitialPhases[]] // Chop </code></pre> <p>Next, I perform numerical solution of the system on the interval <code>[0, T]</code> with pre-defined <code>T</code> and for a fixed constant <code>g</code>. I obtain the set of function <code>f[i][t]</code> and compute the cross-ratio as the function of time for my pre-choosen oscillators,</p> <pre><code>KuramotoCrossRatio[t_] := Re[crossratio[f[t], f[t], f[t], f[t]]] </code></pre> <p>From analytical treatment, I can show that <code>KuramotoCrossRatio[t]</code> should be simply the constant, which coincides with <code>KuramotoCrossRatioTest</code>. However, testing all the methods from <a href="https://math.stackexchange.com/questions/83156/what-are-the-wolfram-mathematica-ndsolve-function-methods">this</a> question, I concluded that all the methods are imperfect, despite any manipulations with <code>WorkingPrecitions</code> and <code>PrecisionGoal</code>. I have obtained the best results with implicit methods (see the fig. below).</p> <p><a href="https://i.stack.imgur.com/2VTBR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2VTBR.png" alt="implicitmethods" /></a></p> <p>As I understand, for a system with an integral of motion implicit methods and leapfrog methods are appropriate to capture the integral of motion. From <a href="https://mathematica.stackexchange.com/questions/257519/how-to-ndsolve-system-with-motion-integral">my old question</a>, I know that there is the <a href="https://reference.wolfram.com/language/tutorial/NDSolveProjection.html" rel="nofollow noreferrer">method</a> <code>&quot;Projection&quot;</code> by it requires to specify an explicit form of an integral of motion.</p> <p><strong>So, my question is following</strong>: consider that I have a dynamical system and I has a set of possible &quot;candidates&quot; for integral of motion, how should I use <code>NDSolve</code> in order to test my &quot;candidates&quot;?</p> <p>If I will be completely sure that they are integrals of motion, I can simply use <code>&quot;Projection&quot;</code> method or <code>&quot;SymplecticPartitionedRungeKutta&quot;</code>. However, I does not know my &quot;candidates&quot; are indeed integrals of motion or not.</p> https://mathematica.stackexchange.com/q/268659 1 How to take a derivative of a function with respect to another function inside the function? Victor Nielsen https://mathematica.stackexchange.com/users/82214 2022-05-24T15:08:15Z 2022-05-24T15:08:15Z <p>I have these two equations:</p> <pre><code>p[x_, y_, t_, ta_, f_, fa_, u_] := (E^\[Omega]*(\[Epsilon] + 1)*((y - (f + fa) - (t + ta)*x)^(1 - \[Gamma])/(1 - \[Gamma]) - u))^(1/(\[Epsilon] + 1)); q[x_, y_, t_, ta_, f_, fa_, u_] := (1 - \[Gamma])^(\[Gamma]/(1 - \[Gamma]))*E^\[Omega]*p[x, y, t, ta, f, fa, u]^(\[Epsilon] + 1)*((E^\[Omega]*p[x, y, t, ta, f, fa, u]^(\[Epsilon] + 1))/(\[Epsilon] + 1) + u)^(\[Gamma]/(1 - \[Gamma])); </code></pre> <p>I need to make a test with the Slutsky equation:</p> <pre><code>dq/dp + q*dq/dy &lt; 0 </code></pre> <p>What I have tried so far:</p> <pre><code>Slutsky[x_, y_, t_, ta_, f_, fa_, u_] := D[q[p], p] + q[x]*D[q[y], y] #doesn't recognise q[p] or q[y] - I already knew this wasn't going to work Slutsky[x_, y_, t_, ta_, f_, fa_, u_] := D[q[x, y, t, ta, f, fa, u], p] + q[x, y, t, ta, f, fa, u]*D[q[x, y, t, ta, f, fa, u], y] #problem is that p is not a parameter in the function so I also knew this wasn't going to work </code></pre> <p>Question is what would work? Do I have to make p into a parameter?</p> <p>PS. I have parameter numerical values for y, t, ta, f, fa.</p> <p>x follows a gradient from 0 to xbar.</p> <p>u is calculated in model, but I could set it arbitrarily for this test.</p> https://mathematica.stackexchange.com/q/268654 0 WolframClient output convert to python complex array Morgan https://mathematica.stackexchange.com/users/44023 2022-05-24T14:43:07Z 2022-05-24T14:43:07Z <p>I encountered the following issue with <code>WolframClient</code>. I have a <code>my.function</code> file which contains some function that takes some parameters (7 floats) as input and returns a nested list of complex numbers in Mathematica. I want to call it via python and treat the output as a <code>numpy.ndarray</code> of complex numbers. I do the following:</p> <pre><code>with WolframLanguageSession() as session: my_function = session.function(wl.Get(path_to_function)) x = my_function(0.1, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8) print(x) </code></pre> <p>which gives me something like this:</p> <pre><code>((((Complex[-2.9851335011862212, -0.5581051654634444], Complex[-0.34914756979863104, 0.38713532072098944], Complex[0.02846108320428109, 0.03283335816887564]), (Complex[2.9114417580613257, -0.058550143608501304], Complex[0.041982819472082836, -0.2399283469968325], 0), (Complex[-0.29788041688768496, 0.16668305088796254], 0, 0)), ((Complex[1.607048536309744, 0.054911153529431656], Complex[0.03322853020335367, -0.11167319057887276], 0), (Complex[-0.3015173117518156, 0.12541388543997334], 0, 0), (0, 0, 0)), ((Complex[-0.07510109944668442, 0.02144870241235377], 0, 0), (0, 0, 0), (0, 0, 0))), (((Complex[1.7446313085976066, 0.9785287503847628], Complex[0.15511366918115133, -0.17146659375916984], 0), (Complex[-0.6471782663657613, -0.03367309746041122], 0, 0), (0, 0, 0)), ((Complex[-0.3056298195051441, -0.05182365243220163], 0, 0), (0, 0, 0), (0, 0, 0)), ((0, 0, 0), (0, 0, 0), (0, 0, 0))), (((Complex[-0.25138505704186276, -0.17724520875129096], 0, 0), (0, 0, 0), (0, 0, 0)), ((0, 0, 0), (0, 0, 0), (0, 0, 0)), ((0, 0, 0), (0, 0, 0), (0, 0, 0)))) </code></pre> <p>which python parses as a tuple, which is fine because I can convert a tuple to array. However, I've got a problem with the complex numbers: each non-zero element of the tuples is a <code>wolframclient.language.expression.WLFunction</code> which I don't know how to convert to a python number. How do I solve this?</p> https://mathematica.stackexchange.com/q/268653 2 Filling the space with rectangles ralph https://mathematica.stackexchange.com/users/47286 2022-05-24T14:38:18Z 2022-05-24T14:38:18Z <p>The problem concerns filling the matrix m x n with rectangles.</p> <pre><code>m = 100; n = 100; m1 = RandomReal[{0, 1}, {m, n}]; alpha = Pi/4.; (*The angle of the rectangle to the horizontal (vertical).*) (*direction of first side of the rectangle*) e1 = {Cos[alpha], Sin[alpha]}; (*e1=RandomPoint[Circle[]]*) (*direction of the second side of the rectangle*) e2 = RotationTransform[Pi/2][e1]; (*half the length of the first side of the rectangle*) halflength1 = 5;(*RandomReal[{1,m/2}];*) (*half the length of the second side of the rectangle*) halflength2 = 15;(*RandomReal[{1,n/2}];*) ogr1 = Ceiling[(halflength1)*Cos[alpha] + (halflength2)*Sin[alpha]];(*constraints on rectangular centers to be full in the matrix.*) ogr2 = Ceiling[(halflength2)*Cos[alpha] + (halflength1)*Sin[alpha]]; </code></pre> <pre><code>X = (2*halflength1)/Sin[alpha]; center = Table[{ogr1, ogr1 + i*X}, {i, 0, 5}] (*Center positions of horizontally non-overlapping rectangles*) </code></pre> <pre><code> pts = Tuples[{Range[m], Range[n]}]; (*The following vector has a 1 at positions that belong to the \ rectangle;other entries are 0.*) picker = Times[UnitStep[halflength1 - Abs[pts.e1 - center[[i]].e1]], UnitStep[halflength2 - Abs[pts.e2 - center[[i]].e2]]]; (*Pick the coordinates of the points belonging to the rectangle.*) pattern = Pick[pts, picker, 1]; (*Find axis-aligned bounding box (the orange rectangle)*) {xspan, yspan} = Span @@@ (MinMax /@ Transpose[pattern]); (*Use SparseArray to construct the actual matrix.*) result = SparseArray[pattern -&gt; Extract[m1, pattern], {m, n}][[xspan, yspan]]; r1 = Select[Flatten[result], # &gt; 0 &amp;]; r2 = Flatten[Table[Position[m1, r1[[i]]], {i, 1, Length[r1]}], 1]; Rotate[ListPlot[{r2}, PlotRange -&gt; {{0, 101}, {0, 101}}, AspectRatio -&gt; 1, Frame -&gt; True, FrameTicks -&gt; None, PlotStyle -&gt; {RandomColor[], PointSize -&gt; 0.001}, PlotMarkers -&gt; {\[FilledVerySmallSquare], Tiny}], -Pi/2] , {i, Length[center]}] Table[ccc[[i, 1]], {i, 1, Length[ccc]}]; Rotate[Show[%], -Pi/2] </code></pre> <p>We obtain such a series of rectangles: <a href="https://i.stack.imgur.com/3caQM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3caQM.jpg" alt="enter image description here" /></a></p> <p>The question is. How to define the 'center' set to obtain such a series of rectangles as in this graph? (I made it by hand :)): <a href="https://i.stack.imgur.com/ziScr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ziScr.png" alt="enter image description here" /></a></p> <p>So how to fill the matrix with full non-overlapping rectangles with given side lengths and inclination angle alpha.</p> https://mathematica.stackexchange.com/q/268651 5 Fastest way to generate {{a,a},{a,b},{a,c},{b,b},{b,c},{c,c}} from {a,b,c} Thrash https://mathematica.stackexchange.com/users/86530 2022-05-24T14:34:31Z 2022-05-25T00:01:17Z <p>What is the fastest way to generate <code>{{a,a},{a,b},{a,c},{b,b},{b,c},{c,c}}</code> from <code>l={a,b,c}</code>? I've tried</p> <p><code>Flatten[Table[{l[[i]],l[[j]]},{i,Length@l},{j,i,Length@l}],1]</code></p> <p>but is there a faster and perhaps more elegant way (maybe with <code>Tuples</code>)?</p> https://mathematica.stackexchange.com/q/268650 0 Inline labels in a plot surrutiaquir https://mathematica.stackexchange.com/users/81788 2022-05-24T14:24:30Z 2022-05-24T14:24:30Z <p>Not quite sure if this is even possible, but I assume this is the right place to ask. In Python, as discussed on <a href="http://stackoverflow.com/questions/16992038/inline-labels-in-matplotlib">this question</a>, it is possible to add the corresponding labels directly over each line, as shown in this picture:</p> <p><a href="https://i.stack.imgur.com/nNn3n.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nNn3n.png" alt="enter image description here" /></a></p> <p>The details of the implementation are available in a <a href="https://github.com/cphyc/matplotlib-label-lines" rel="nofollow noreferrer">Github repository</a>, in case you are wondering how it works.</p> <p>I wonder if there is a way to implement anything similar in Mathematica using some of its built-in functions. Thanks for your suggestions!</p> https://mathematica.stackexchange.com/q/268649 2 Goodness of fit Stan https://mathematica.stackexchange.com/users/86170 2022-05-24T14:04:06Z 2022-05-24T18:08:37Z <p>I want to evaluate the goodness of two sets or more fitting parameters, using Rsquared and RMSE (root mean square error), Then how to code?)</p> <pre><code> data = { {43.68, 1.}, {206.42, 0.76}, {398.11, 0.58}, {1019.47, 0.42}, {1910.44, 0.33}, {2964.39, 0.26}, {4116.84, 0.22}, {5318.17, 0.19}, {6505.9, 0.16}, {7709.48, 0.15}, {8827.55, 0.13}, {9984.18, 0.12}, {11015.08, 0.11}}; model = Sum[4/((2*k + 1)*Pi)*1(*c0*)* MittagLefflerE[β, ((-d)* (2*k + 1)^2*π^2*t^β)]* Sin[(2*k + 1)*Pi*1/2], {k, 0, 10}]; M = NonlinearModelFit[data, model, {{β, 0.7}, {d, 0.0002}}, t]; Show[{ListPlot[data, PlotStyle -&gt; Black], Plot[M // Normal, {t, data[[1, 1]], data[[-1, 1]]},PlotStyle -&gt; Red, PlotRange -&gt; All]}] </code></pre> <p>In the above case, I use the fitting parameter set <code>{β=0.7,d=0.0002}</code> and get the fitting curve shown below.</p> <p><a href="https://i.stack.imgur.com/jxXFHm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jxXFHm.png" alt="{β=0.7,d=0.0002} fitting" /></a></p> <p>In another case, I use the fitting parameter set <code>{β=0.71,d=0.0029}</code> and get the fitting curve shown below.</p> <p><a href="https://i.stack.imgur.com/P3MtUm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P3MtUm.png" alt="{β=0.71,d=0.0029} fitting" /></a></p> <p>The two curves are quite similar, I need to use quantity criteria like &quot;R-squared&quot; and RMSE to assess the goodness of fitness. I searched in the documentation, and it seems no RMSE property is available.</p> <p><strong>How can I get the &quot;RMSE&quot; and &quot;R-squared&quot; from my FittedModel ?</strong></p> https://mathematica.stackexchange.com/q/268643 12 Which Mathematica versions have changed WolframLibraryVersion? Szabolcs https://mathematica.stackexchange.com/users/12 2022-05-24T12:39:47Z 2022-05-24T13:02:47Z <p>A LibraryLink library compiled with headers having a certain <code>WolframLibraryVersion</code> will not work with Mathematica versions that support only earlier <code>WolframLibraryVersion</code>s.</p> <p>For example, a library compiled with M12.0 (<code>WolframLibraryVersion == 5</code>) will work not only in 12.0 but also in 12.1–13.0 (<code>WolframLibraryVersion == 6</code>). However, it will not work in 11.3 (<code>WolframLibraryVersion == 4</code>).</p> <p>Which Mathematica versions use which <code>WolframLibraryVersion</code>?</p> https://mathematica.stackexchange.com/q/268640 6 Scalloped edges to Plot3D with Disc domain quixot https://mathematica.stackexchange.com/users/86659 2022-05-24T11:40:59Z 2022-05-24T13:45:33Z <p>I'm running into problems with a weird edges to my Plot3D with a Disc domain. MWE:</p> <pre><code>Plot3D[(x^2 + y^2 - 100)^2, {x, y} \[Element] Disk[{0, 0}, 13.5], PlotPoints -&gt; 100] </code></pre> <p>which produces</p> <p><a href="https://i.stack.imgur.com/pLukh.png" rel="noreferrer"><img src="https://i.stack.imgur.com/pLukh.png" alt="enter image description here" /></a></p> <p>I don't know where the scalloping is coming from. It disappears for low PlotPoints, e.g. 10, but I need high plotpoints for the colour scheme I'm using. I've tried using Show[] with a slightly lower PlotRange to try to clip them off, but they remain.</p> <p>I would dearly love a version with a crisp straight edge for my paper - would be grateful for any fixes!</p> https://mathematica.stackexchange.com/q/268639 1 Boolean constraint in an interval for FindMinimum edmateosg https://mathematica.stackexchange.com/users/77688 2022-05-24T11:07:47Z 2022-05-24T14:20:49Z <p>I have a function with a large number of variables that I am trying to minimize subject to some constraints, but for simplicity let us say that it only has two variables, f[x, y]. The constraint is that another function, g[z], must be positive in the interval given by x and y (in my problem I usually have around 200 variables, and it needs to be monotonical in the interval between the minimum and the maximum)</p> <p>Edit: Following the comment by Daniel Huber, let's define</p> <pre><code>f[x_, y_] := x^3 + 2 x y + 3 g[z_] := z^2 - 2 z </code></pre> <p>where f is to be minimized in the region {x, y} [Element] Rectangle[{0, 0}, {4, 4}] subject to g[z] &gt;= 0 for all z in the region Interval[{Min[x_solution, y_solution], Max[x_solution, y_solution]}]</p> <p>If we did not have this constraint we would find that</p> <pre><code>Minimize[{f[x, y], constraint}, {x, y}]\[Element] Rectangle[{0, 0}, {4, 4}] (* {3, {x -&gt; 0, y -&gt; 2}} *) </code></pre> <p>But g[z] &lt; 0 for z ∈ Interval[{0, 2}]</p> <p>Instead, the solution that I am looking for would be {19, {x -&gt; 2, y -&gt; 2}}</p> <p>In my problem, the coefficients in the polynomial of g[z] are part of the variables that I am trying to optimize, while the rest of the variables are what defines the interval in which I want this polynomial to be positive (so I will take the minimum and maximum of these variables when defining the interval, similar to taking the minimum and maximum of x and y in this toy model), and it is not easy to find workarounds like studying the behavior of g[z] before optimizing f[x,y].</p> <p>Additionally, my function involves a lot of terms and Minimize cannot solve it, so I would prefer solutions involving FindMinimum instead.</p> <p>I hope the question is clearer now!</p> https://mathematica.stackexchange.com/q/268636 4 Solving symbolically a trascendental equation containing an exponential umby https://mathematica.stackexchange.com/users/58367 2022-05-24T08:46:53Z 2022-05-24T12:58:44Z <p>Is it possible to solve symbolically this equation for <span class="math-container">$x$</span>: <span class="math-container">$$\exp \left(-x^2\right)=\frac{c_1}{\sqrt{c_2-c_3 x}}$$</span></p> <pre><code>Exp[-x^2] == c1/Sqrt[c2 - c3 x] </code></pre> <p><span class="math-container">$c_1$</span>, <span class="math-container">$c_2$</span> and <span class="math-container">$c_3$</span> are positive constants, with <span class="math-container">$\frac{c_1}{\sqrt{c_2}}&lt;1$</span>. I am interested in the negative solution, <span class="math-container">$x&lt;0$</span>. A typical plot of the two functions at the RHS and LHS of the equation is <a href="https://i.stack.imgur.com/HpS0P.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HpS0P.jpg" alt="plot of the two sides of the equation" /></a></p> <p>I tried an expansion at zero to the second order of the two sides of the equation, but the result besides being complicated does not seem to give a good approximation of the result. On the other side, it is easy to find a numerical solution to the problem:</p> <pre><code>NSolve[Exp[-x^2] == c1/Sqrt[c2 - c3 x] &amp;&amp; x &lt; 0, x] </code></pre> <p>Thanks in advance.</p> https://mathematica.stackexchange.com/q/268635 1 Convert a polynomial to a vector [duplicate] Md Salem https://mathematica.stackexchange.com/users/84405 2022-05-24T08:28:49Z 2022-05-24T13:55:11Z <p>I am trying to transform a generated polynomial terms into a vector, I used the command 'MonomialList',</p> <pre><code>X = x - (2 x^3/a^2) + (x^4/a^3); Y = y - (2 y^3/b^2) + (y^4/b^3); u = (y^2 - b*y)*(2*x - a); v = (x^2 - a*x)*(2*y - b); w = X*Y; L= MonomialList[u] M= MonomialList[v] N= MonomialList[w] </code></pre> <p>the result of such code was :</p> <pre><code>{a b y, -a y^2, -2 b x y, 2 x y^2} {a b x, -2 a x y, -b x^2, 2 x^2 y} {(x^4 y^4)/(a^3 b^3), -((2 x^4 y^3)/(a^3 b^2)), ( x^4 y)/a^3, -((2 x^3 y^4)/(a^2 b^3)), (4 x^3 y^3)/( a^2 b^2), -((2 x^3 y)/a^2), (x y^4)/b^3, -((2 x y^3)/b^2), x y} </code></pre> <p>The results are so far so good, the problem is arisen when I try to treat (L,M,or N) as vectors</p> <pre><code>Transpose [L] </code></pre> <p>I receive such result :</p> <pre><code>Transpose[{a b y, -a y^2, -2 b x y, 2 x y^2}] </code></pre> <p>with error message :</p> <pre><code>Transpose: The first two levels of {a b y,-a y^2,-2 b x y,2 x y^2} cannot be transposed. </code></pre> <p>I tried to use next code to over come this problem :</p> <pre><code> L = {MonomialList[u]} </code></pre> <p>whose result was</p> <pre><code>{{2. x y^2, -0.6 x y, -0.5 y^2, 0.15 y}} </code></pre> <p>when I tried to get the transpose[L] :</p> <pre><code>{{2. x y^2}, {-0.6 x y}, {-0.5 y^2}, {0.15 y}} </code></pre> <p>The problem is solved</p> https://mathematica.stackexchange.com/q/268634 1 Numerical solution of an ordinary integro-differential equation Asatur Khurshudyan https://mathematica.stackexchange.com/users/54962 2022-05-24T07:18:11Z 2022-05-24T23:16:40Z <p>I am trying to solve the following integro-differential equation: <span class="math-container">$$a(\varepsilon) f'(\varepsilon) + b(\varepsilon) f(\varepsilon) + \int_{\varepsilon}^{\varepsilon + \varepsilon_1} R_1(\epsilon) f(\epsilon) d\epsilon - \int_{\varepsilon - \varepsilon_2}^{\varepsilon} R_2(\epsilon) f(\epsilon) d\epsilon = 0,$$</span> where <span class="math-container">$\varepsilon_1 = 10$</span>, <span class="math-container">$\varepsilon_2 = 20$</span>.</p> <p>Note that the reduction of this equation into a second-order ODE is possible, but is much harder to solve. See, e.g., <a href="https://mathematica.stackexchange.com/questions/268104/numerical-solution-of-an-advance-delay-ode-with-multiple-advances-and-delays">this question</a>.</p> <p>Taking</p> <pre><code>eps1 = 10; eps2 = 20; epsmin = .025; epsmax = 150; a[eps_] := 1 + eps b[eps_] := eps^1.4 R1[eps_] := Piecewise[{{eps, eps1 &lt;= eps &lt;= epsmax}}, 0] R2[eps_] := Piecewise[{{eps, eps2 &lt;= eps &lt;= epsmax}}, 0] </code></pre> <p>We know that <code>f[eps] &gt; 0</code> for <code>epsmin &lt;= eps &lt;= epsmax</code>, and that <code>f[eps] = 0</code> for <code>eps &lt;= epsmin</code> and <code>eps &gt;= epsmax</code>. For <code>eps &gt;= epsmax</code>, all derivatives of <code>f[eps]</code> also become 0. Also,</p> <pre><code>Integrate[Sqrt[eps] f[eps], {eps, epsmin, epsmax}] == 1; </code></pre> <p>I have tried to use <code>NDSolve</code> with <code>NIntegrate</code> as follows:</p> <pre><code>solBW = NDSolve[{a[eps]f'[eps] + b[eps]f[eps] + NIntegrate[R1[y]f[y],{y,eps,eps + eps1}] - NIntegrate[R2[y]f[y],{y, eps - eps2, eps}] == 0, f[epsmax] == 0}, f, {eps, epsmax, epsmin}]; </code></pre> <p>but it returns</p> <pre><code>NIntegrate: y = eps is not a valid limit of integration. </code></pre> <p>Any hint on how to solve this equation numerically is appreciated.</p> https://mathematica.stackexchange.com/q/268625 4 Parts of a Piecewise Matrix Function in NDSolve CelestialMelody https://mathematica.stackexchange.com/users/86654 2022-05-24T00:40:34Z 2022-05-24T16:31:18Z <p>First time posting.</p> <p><strong>Reproducing the Problem</strong></p> <p>I'm relatively new to Mathematica (using v.12.3), and working on a project. My problem can be reproduced with this.</p> <pre><code>m[x_] := {{x, 0}, {0, x}} f[x_] := Piecewise[{{m[x], x &lt;= 5}}, m] test = NDSolve[{y'[t] == f[t][[1, 1]], y == 0}, y, {t, 0, 10}] </code></pre> <p>Outside of NDSolve, <code>f[t][[1,1]]</code> evaluates as expected using the Piecewise function (i.e., <code>f[[1,1]] = m[[1,1]]</code> but <code>f[[1,1]] = m[[1,1]]</code>).</p> <p>However, NDSolve does not seem to evaluate the Piecewise function before attempting to use it, as the stack trace gives:</p> <pre><code>NDSolve[{Derivative[y][t] == {{{t, 0}, {0, t}}, t &lt;= 5}, y == 0}, y, {t, 0, 10}] </code></pre> <p><strong>Attempted Solutions &amp; Workarounds</strong></p> <p>Moving the Piecewise statement within NDSolve seems to produce the expected result.</p> <pre><code>m[x_] := {{x, 0}, {0, x}} f[x_] := m[x] test = NDSolve[{ y'[t] == Piecewise[{{f[t][[1, 1]], t &lt;= 5}}, m[[1, 1]]], y == 0}, y, {t, 0, 10}] </code></pre> <p>I also tried <code>If</code> statements:</p> <pre><code>m[x_] := {{x, 0}, {0, x}} f[x_] := If[x &gt;= 10, m[x], m] test = NDSolve[{y'[t] == f[t][[1, 1]], y == 0}, y, {t, 0, 10}] </code></pre> <p>However, this appears to ignore the <code>If</code> statement entirely when comparing the outputs using <code>Plot[y[t] /. test, {t, 0, 10}]</code>.</p> <p>I have looked around extensively on StackExchange and the documentation for solutions, but haven't come up with much besides a suspicion that it's</p> <ul> <li>something to do with a Hold or Delay property that I don't know about, and/or</li> <li>something to do with syntax I don't know about, and/or</li> <li><a href="https://mathematica.stackexchange.com/questions/250329/solving-an-equation-matrix-with-ndsolve">something to do with how NDSolve works?</a></li> </ul> <p>I would appreciate an explanation for why this behavior occurs (or something I can look up to find that information myself; maybe I don't know what to look for), as I've been struggling for some 8+ hours on this. Thank you!</p> <p><strong>Edit:</strong> All excellent responses; thank you so much!</p> https://mathematica.stackexchange.com/q/268604 4 Abs applied with explicit map not giving same result as built in threading ergodic_tortoise https://mathematica.stackexchange.com/users/86651 2022-05-23T15:18:11Z 2022-05-24T23:30:18Z <p>I was making a code change that required me to change some code that looked like</p> <pre><code>Abs[list] </code></pre> <p>to something that looked like</p> <pre><code>Map[Abs, list] </code></pre> <p>During testing I discovered that these two methods gave slightly different results. Some code to illustrate:</p> <pre><code>l1 = RandomComplex[{-1 - I, 1 + I}, 1000000]; Abs[l1] - Map[Abs, l1] // Norm </code></pre> <p>The output I get from running the code above in Mathematica 12.0.0.0 is on the order of 10^-14. My understanding was Abs &quot;threading&quot; over a list was the same as mapping Abs on each element of that list so I was expecting an output of 0. Can someone correct my understanding or otherwise explain what is the difference between these two methods?</p> https://mathematica.stackexchange.com/q/268573 6 How to detect chains (sequence of degree 2 vertices ) in a graph? userrandrand https://mathematica.stackexchange.com/users/86543 2022-05-22T23:41:30Z 2022-05-25T01:11:50Z <p>I am interested in finding the positions of &quot;chains&quot; (sequences of vertex degree 2 vertices) in a graph. I plan on collapsing these chains later to vertices with labels indicating that they are collapsed chains.</p> <p>For example, I would like the following input-output.</p> <p>Input:</p> <pre><code>Graph[{1 \[DirectedEdge] 2, 2 \[DirectedEdge] 3, 3 \[DirectedEdge] 4, 4 \[DirectedEdge] 5, 6 \[DirectedEdge] 7, 7 \[DirectedEdge] 8, 5 \[DirectedEdge] 8, 8 \[DirectedEdge] 9}] </code></pre> <p><a href="https://i.stack.imgur.com/EIwuM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EIwuM.jpg" alt="graph" /></a></p> <p>Output:</p> <pre><code>{&quot;Chain1&quot; -&gt; Graph[{1 \[DirectedEdge] 2, 2 \[DirectedEdge] 3, 3 \[DirectedEdge] 4, 4 \[DirectedEdge] 5, 5 \[DirectedEdge] 6}], &quot;Chain2&quot; -&gt; Graph[{1 \[DirectedEdge] 2, 2 \[DirectedEdge] 3}], HighlightGraph[ Graph[{Labeled[1, &quot;Chain1&quot;], Labeled[3, &quot;Chain2&quot;]}, {1 -&gt; 2, 3 -&gt; 2, 2 -&gt; 4}], {1, 3}]} </code></pre> <p><a href="https://i.stack.imgur.com/3jdIE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3jdIE.jpg" alt="list_result" /></a></p> <p><strong>Possible methods to implement the code</strong></p> <p>There are some methods that come to mind but I am interested in whether anyone here has an idea on how to implement this in an easy and elegant way. Perhaps that requires utilizing some of the fancy pre-made Mathematica graph functions.</p> <p>A direct solution could consist of using EdgeList and a For loop that starts at different positions in the graph and stops whenever it encounters a vertex that has a degree larger than 2. This sounds inefficient.</p> <p>Another possibility could be to use AdjacencyMatrix and delete chains found in the matrix. The issue is that it does not seem to be easy to find sequences in the matrix that correspond to chains in the graph as this depends on the numbering convention of the vertices (maybe I am wrong I did not look into this much).</p> <p><strong>Why do you want to do that ?</strong></p> <p>I want to make a code that creates a symbolic expression for the output of an artificial neural network (I am interested if anyone has a code that already does that).</p> <p>I already made a code that works with simple feedforward networks (NetChain) that contain only ElementwiseLayer and LinearLayer.</p> <p>I would like to use my code for NetChains to replace any chain subgraph in NetGraph with its symbolic functional equivalent and then use these intermediate expressions to compute the full symbolic expression of a network. A typical example would be to replace a network that adds the results of two NetChains by first finding the expressions for the NetChains and then simply adding them.</p> <p><strong>Edit 1</strong></p> <p>In the output example given I would like the two first elements in Chain1 and Chain2 to retain the names of the vertices. The length of the chain is not enough for my purpose.</p> <p><strong>Edit 2</strong></p> <h1>The full procedure incorporating the methods below</h1> <p>I accepted the answer from @Szabolcs as the user's answer utilizes only one function from the IGraph/M package. Hence, this method is likely fast and robust. However, I would like to mention that @lericr's answer is fairly simple and uses only Mathematica built-in functions and so it might represent a more convenient solution for some people. That said, the two solutions differ in terms of the resulting graph. The method of @lericr collapses the chain onto a vertex whereas the method of @Szabolcs collapses the chain onto an edge as I show below.</p> <p>The following contains the codes to collapse/package chains in a graph.</p> <p>Input example:</p> <pre><code>Graph[{1 -&gt; 2, 2 -&gt; 3, 3 -&gt; 4, 5 -&gt; 4, 4 -&gt; 8, 8 -&gt; 9, 9 -&gt; 10, 10 -&gt; 11, 11 -&gt; 12, 12 -&gt; 13, 13 -&gt; 14, 11 -&gt; 15, 15 -&gt; 16, 15 -&gt; 17}, ImageSize -&gt; Small, VertexLabels -&gt; Automatic] </code></pre> <p><a href="https://i.stack.imgur.com/fBGq8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fBGq8.png" alt="input" /></a></p> <p>Output using the method from @lericr:</p> <p><a href="https://i.stack.imgur.com/P6LAW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P6LAW.png" alt="graph" /></a></p> <p>Output using the method from @Szabolcs:</p> <p><a href="https://i.stack.imgur.com/T4nvP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T4nvP.png" alt="output2" /></a></p> <p>The choice between the two is perhaps a matter of semantics, that is, whether the collapsed chain should represent a vertex (for example the vertex 8 in the first output example) or an edge (for example the edge 4-&gt;11). In the following, I will use the method provided by @lericr which has the benefit of using only built-in functions.</p> <p>Following the suggestion of @Szabolcs, the list of collapsed chains can be obtained using**(footnote):</p> <pre><code>chains=WeaklyConnectedGraphComponents[Subgraph[inputgraph, _? (VertexDegree[testGraph2, #] &lt; 3 &amp;)] // EdgeList] </code></pre> <p>Output:</p> <p><a href="https://i.stack.imgur.com/UguMH.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UguMH.jpg" alt="list" /></a></p> <p>The slightly longer method used by @lericr might require less computer time since it does not use patterns but I have not checked.</p> <p>The collapsed chains in the output graph are identified by the first vertex in each chain. These may be extracted using:</p> <pre><code>chainNodes=TreeData /@ GraphTree /@ chains </code></pre> <p>Or the method used by @Ben Izd:</p> <pre><code>chainNodes=Last /@ (VertexInComponent[#, Last@VertexList[#]] &amp;) /@ chains </code></pre> <p>Which is a bit longer to write and more difficult to understand and remember but it was about 200 times faster in my tests involving chains containing over a hundred vertices. Of course, this remark is important only for graphs containing many long chains.</p> <p>Then we may use @Ben Izd's answer where I included the option to highlight the collapsed chains:</p> <pre><code>labels = Array[&quot;Chain&quot; ~~ ToString[#] &amp;, Length @ chainNodes]; AnnotationValue[{outputgraph, chainNodes}, VertexLabels] = labels; Append[MapThread[Rule, {labels, chains}], HighlightGraph[Outputgraph, chainNodes]] </code></pre> <p>which leads to the final result:</p> <p><a href="https://i.stack.imgur.com/JXW4k.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JXW4k.jpg" alt="res" /></a></p> <p>** Footnote : The list chains is equivalent to @lericr's chainSubgraphs I believe. Also, EdgeList was used to remove any lone wolf vertices from the disconnected graphs. Equivalently one could also use VertexDelete as in @lericr's answer:</p> <pre><code>WeaklyConnectedGraphComponents[ VertexDelete[inputgraph, _?(VertexDegree[inputgraph, #] &gt; 2 &amp;)] // EdgeList] </code></pre> <p>This VertexDelete code has about the same speed as the Subgraph one when using the input examples above.</p> https://mathematica.stackexchange.com/q/268461 0 Identifying the intersection between a ConditionalExpression and a parametric curve Patricio https://mathematica.stackexchange.com/users/60362 2022-05-20T15:38:51Z 2022-05-24T21:36:53Z <p>I'm trying to determine the intersection of lines over a surface (if they exist). My problem is that one of the lines is defined as a conditional expression and for the others I only have a parametric description. In particular, I have two surfaces <a href="https://i.stack.imgur.com/iaLpP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iaLpP.png" alt="see image" /></a> and I've represented their intersection as the red line. This is the conditional expression</p> <pre><code>{{q -&gt; ConditionalExpression[Sqrt[8 - 3 q^2]/Sqrt, 0 &lt; q &lt; 2 Sqrt[2/3]], q -&gt; ConditionalExpression[Sqrt[1 + q^2]/Sqrt, 0 &lt; q &lt; 2 Sqrt[2/3]]}} </code></pre> <p>What I'd like to do is to identify the points where the blue and the green lines cross the red line. Both the blue and the green lines go through those points on the surface where one of the slopes is -1 and I've probably gone through too much of a hassle to draw them. Be it as it may, the best I've been able to do is a parametric plot, so I'm not sure how to proceed to obtain their intersections with the red line.</p> <p>My code is</p> <pre><code>ClearAll[&quot;Global*&quot;] X = {{1, 4}, {2, 4}, {4, 4}}; qVec = Array[q, 3]; kVec = {10, 18}; a = 1/2; needs = Transpose[X].qVec^(1/a); max = Table[(Min[kVec[]/X[[i, 1]], kVec[]/X[[i, 2]]])^a, {i, 1, 3}]; (*This defines the surfaces*) con = Table[ContourPlot3D[needs[[i]] == kVec[[i]], {q, 0, (kVec[[i]]/X[[1, i]])^a}, {q, 0, (kVec[[i]]/X[[2, i]])^a}, {q, 0, (kVec[[i]]/X[[3, i]])^a}, Mesh -&gt; None], {i, 1, 2}]; (* This defines the intersection of the surfaces (red line)*) inter = ParametricPlot3D[qVec /. Solve[Flatten[{needs == kVec, Thread[qVec &gt;= 0]}], Rest@qVec, Reals] // Evaluate, {q, 0, max[]}, PlotStyle -&gt; Red]; (* This defines the green and blue lines*) lines = Table[ sol = Solve[D[needs[[j]], q] == D[needs[[j]], q[i]], q][]; f3 = (q /. sol) /. {q -&gt; x, q -&gt; x}; f2 = If[i == 1, ((q[3 - i] /. SortBy[Re@*Last]@Solve[needs[[j]] == kVec[[j]], q[3 - i]][]) /. sol) /. q -&gt; x, x]; f1 = If[i == 1, x, ((q[3 - i] /. SortBy[Re@*Last]@Solve[needs[[j]] == kVec[[j]], q[3 - i]][]) /. sol) /. q -&gt; x]; Solve[If[i == 1, f2 == 0, f1 == 0]]; m = x /. SortBy[Re@*Last]@Solve[If[i == 1, f2 == 0, f1 == 0]][]; ParametricPlot3D[{f1, f2, f3}, {x, 0, m}, PlotStyle -&gt; If[j == 1, Blue, Green]], {j, 1, 2}, {i, 1, 2}]; (*This shows the image I've included above*) Table[Show[{con[[i]], lines[[i, All]], inter}], {i, 1, 2}] </code></pre> <p>Feel free to comment on any other aspect of the code. Thanks</p> https://mathematica.stackexchange.com/q/267480 0 How to find PlanarAngle[] across periodic boundaries? TumbiSapichu https://mathematica.stackexchange.com/users/53229 2022-04-28T01:28:39Z 2022-05-24T21:14:18Z <p>Suppose we have a collection of points selected as being within a certain radius (0.1) of <code>myCenterPoint</code>:</p> <pre><code>myCenterPoint = {0.48536, 0.496745}; myCenterNeighbors = {{0.48506, 0.518851}, {0.467608, 0.51639}, {0.456715, 0.489564}, {0.523108, 0.489627}, {0.448557, 0.485287}, {0.432191, 0.479128}, {0.545804, 0.506127}, {0.435738, 0.534355}, {0.438056, 0.538347}, {0.484009, 0.425348}, {0.549424, 0.462288}, {0.562333, 0.500577}, {0.409715, 0.51475}, {0.460376, 0.421197}, {0.540092, 0.438462}, {0.405604, 0.485177}, {0.560972, 0.534108}, {0.548135, 0.553546}, {0.457615, 0.581859}, {0.425488, 0.427731}, {0.478787, 0.404865}, {0.550746, 0.430695}, {0.404494, 0.44804}, {0.399277, 0.542863}}; </code></pre> <p>All points lie within a <span class="math-container">$x$</span>,<span class="math-container">$y$</span> range between <span class="math-container">$0$</span> and <span class="math-container">$1$</span>, the <code>domainRange</code>. Now, I'd like to compute the <code>PlanarAngle[]</code> between the central point and every other neighbor. This is done by:</p> <pre><code>domainRange={0.0, 1.0}; centralAngles = Table[PlanarAngle[myCentralPoint -&gt; {{domainRange[], myCenterNeighbors[][]}, myCenterNeighbors[[i]]}], {i, 1, Length[myCenterNeighbors]}]; </code></pre> <p>We can visualize that the angles indeed go through each point, by drawing arrows across them:</p> <pre><code>radiusArrow = 0.2; Show[ListPlot[myCenterNeighbors, AspectRatio -&gt; Automatic, PlotRange -&gt; {{0, 1}, {0, 1}}], Graphics[{Red, Arrow[AnglePath[myCenterPoint, {{radiusArrow, #}}] &amp; /@ centralAngles]}]] </code></pre> <p>Getting:</p> <p><a href="https://i.stack.imgur.com/xi6OB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xi6OB.png" alt="enter image description here" /></a></p> <p>Now, I have done the same for a point that is in the periphery of the spatial domain, using a distance function for periodic boundaries (meaning, the <span class="math-container">$radius&lt;0.1$</span> neighborhood is calculated across the boundaries). My question is, how could I get the angles that take into consideration the periodicity of this domain? The solution should use the <a href="https://reference.wolfram.com/language/ref/PlanarAngle.html" rel="nofollow noreferrer">PlanarAngle[]</a> function if possible.</p> <p>Applying the same process as above is --of course-- a failure:</p> <pre><code>myPeripheryPoint = {0.00841536468074966, 0.002197018919080307}; myPeripheryNeighbors = {{0.03229560949868793, 0.9865069071458752}, {0.9795340627801099, 0.0020868182730364726}, {0.03858378647524385, 0.012525407762965068}, {0.9913160172244748, 0.9570079562439078}, {0.9917737197180683, 0.04923062576084303}, {0.05054580682579313, 0.03983763666940843}, {0.9848092367462769, 0.9487060792639312}, {0.9919193024256374, 0.9443507696946527}, {0.06593430284785717, 0.9802315321816846}, {0.03063567167293657, 0.9399087243621003}, {0.07729526444337176, 0.011791675915653554}, {0.9434979787548483, 0.9682050073234711}, {0.9829522482069939, 0.9333879581233924}, {0.937958402932543, 0.023490997900727173}, {0.036769273517222034, 0.9335221301932126}, {0.9893277043935138, 0.9297962874690391}, {0.980900667782586, 0.9300759568484791}, {0.930144399230207, 0.017422280608305307}, {0.03275323456438972, 0.08278995189636573}, {0.0905953216509523, 0.02752181180818436}, {0.0925328147605804, 0.02146492818209489}, {0.09764014967822088, 0.9844617574268106}, {0.9423197762714688, 0.06654711398560131}, {0.08407855645557638, 0.0638776330353239}, {0.04786712113942193, 0.09224899111632401}, {0.9251440827682063, 0.9476726186386728}, {0.05288034131659658, 0.09169421967972102`}}; peripheryAngles = Table[PlanarAngle[ myPeripheryPoint -&gt; {{domainRange[], myPeripheryPoint[]}, myPeripheryNeighbors[[i]]}], {i, 1, Length[myPeripheryNeighbors]}]; radiusArrow = 0.18; Show[Graphics[{Red, Arrow[AnglePath[myPeripheryPoint, {{radiusArrow, #}}] &amp; /@ peripheryAngles]}, AspectRatio -&gt; Automatic, PlotRange -&gt; {{0.0, 1.0}, {0.0, 1.0}}, Frame -&gt; True, FrameStyle -&gt; Directive[Black, 14]], ListPlot[myPeripheryNeighbors]] </code></pre> <p><a href="https://i.stack.imgur.com/59VFH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/59VFH.png" alt="enter image description here" /></a></p> <p>So, we'd end up with angles that go beyond the current domain, like these blue ones, corresponding to the direction of the points that lie out of the domain:</p> <p><a href="https://i.stack.imgur.com/tbYBx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tbYBx.png" alt="enter image description here" /></a></p> <p>Thank you!</p> <p>Edit1: If it's relevant --but I don't think so--, the way the distance from <code>somePoint</code> to <code>allOtherPoints</code> was calculated as follows:</p> <pre><code>(*To compute distance with periodic boundaries*) myDistFunct[a_, b_, domainLength_] := Norm@Mod[a - b, domainLength, -domainLength/2] (*The actual computation*) NearestTo[somePoint, {All, radiusDistance}, DistanceFunction -&gt; (myDistFunct[##, domainRange[]] &amp;)][ allOtherPoints -&gt; {&quot;Index&quot;, &quot;Element&quot;, &quot;Distance&quot;}] </code></pre> <p>Which was adapted from <a href="https://mathematica.stackexchange.com/questions/33988/imposing-a-periodic-boundary-condition-in-nearest-neighbour-search">this answer</a>.</p> https://mathematica.stackexchange.com/q/266362 6 Finding the roots of Abs[Hypergeometric1F1[1/4 (3 - (2 x)/I), 1.5, I]]=0 lucky https://mathematica.stackexchange.com/users/85926 2022-04-08T02:17:51Z 2022-05-24T21:45:31Z <p>I want to solve for the first 100 or more zeros of Abs[Hypergeometric1F1[1/4 (3 - (2 x)/I), 1.5, I]]=0;</p> <p>The following code is my simple attempt：</p> <pre><code>a = 2000; Quiet@FindRoot[Abs[Hypergeometric1F1[1/4 (3 - (2*x)/I), 1.5, I]] == 0, {x, #, 0, a}] &amp; /@ Range[a] //Values//Flatten//Round[#, 0.001]&amp;//Sort//DeleteDuplicates </code></pre> <p>But I lose some roots when solving for more roots</p> <p>How can I precisely find more roots</p> https://mathematica.stackexchange.com/q/266264 7 IGraphM on Apple Silicon? Henrik Schumacher https://mathematica.stackexchange.com/users/38178 2022-04-06T07:46:38Z 2022-05-24T14:59:42Z <p>I recently got a new laptop with Apple's M1 Max processor and now the IGraphM installer</p> <pre><code>Get[&quot;https://raw.githubusercontent.com/szhorvat/IGraphM/master/IGInstaller.m&quot;] </code></pre> <p>returns</p> <p><a href="https://i.stack.imgur.com/M3Qqf.png" rel="noreferrer"><img src="https://i.stack.imgur.com/M3Qqf.png" alt="enter image description here" /></a></p> <p>FYI, I ran this in <em>Mathematica</em> version 13.0.1 on macos 12.3.1.</p> <p>So what I'd like to ask:</p> <ol> <li><p>Is it possible to install IGraphM on the M1 architecture? (Given the fact that it runs on ARM-based machines like RaspberryPi, the answer is probably &quot;yes&quot;.)</p> </li> <li><p>How to install it and make it run?</p> </li> </ol> https://mathematica.stackexchange.com/q/264953 0 Solving elliptic integrals in Mathematica Roberto_1986 https://mathematica.stackexchange.com/users/78089 2022-03-10T22:10:50Z 2022-05-25T01:01:36Z <p>I have an integral</p> <p><span class="math-container">$$\int_{a2}^{a1}\frac{dx}{\sqrt{(a1 -x)(a2 - x)(a3 - x)}}$$</span></p> <p>And I'm trying to integrate it with</p> <pre><code>F[u] = (u1 - u)*(u2 - u)*(u3 - u) L = Integrate[1/Sqrt[F[u]], {u, u1, u2}] </code></pre> <p>But it won't run. Any ideas why?</p> https://mathematica.stackexchange.com/q/264891 2 Why does CapForm behave strange with different options? [closed] hana https://mathematica.stackexchange.com/users/82512 2022-03-09T19:13:38Z 2022-05-24T21:48:38Z <p>This CapForm works well:</p> <pre><code>Graphics[{CapForm[&quot;Square&quot;], Thickness[.1], Line[{{-1, -1}, {1, 1}}]}, PlotRange -&gt; 1.5, PlotLabel -&gt; &quot;Square&quot;] </code></pre> <p><a href="https://i.stack.imgur.com/Vx1oq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Vx1oq.png" alt="enter image description here" /></a></p> <p>However, if you change <code>Thickness</code> to <code>0.5</code> you would get a strange cap like this.</p> <pre><code>Graphics[{CapForm[&quot;Square&quot;], Thickness[.5], Line[{{-1, -1}, {1, 1}}]}, PlotRange -&gt; 1.5, PlotLabel -&gt; &quot;Square&quot;] </code></pre> <p><a href="https://i.stack.imgur.com/aNsto.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aNsto.png" alt="enter image description here" /></a></p> <p>Or if you remove <code>PlotRange</code> or change it then you would get a strange cap as well.</p> <pre><code>Graphics[{CapForm[&quot;Square&quot;], Thickness[.1], Line[{{-1, -1}, {1, 1}}]}, PlotLabel -&gt; &quot;Square&quot;] </code></pre> <p><a href="https://i.stack.imgur.com/bQuWC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bQuWC.png" alt="enter image description here" /></a></p> <p>EDIT: I don't need to reopen this as the problem is already solved. However, still wonder why people think this is offtopic. Is it easy to to find from docs? No, unless you already knew it.</p> https://mathematica.stackexchange.com/q/263360 1 Does anyone know how to fix the issue not having the hydrogen atoms accounted for when converting to a .mol file? mostafa100000 https://mathematica.stackexchange.com/users/85013 2022-02-09T19:49:33Z 2022-05-24T21:49:55Z <p>Hi I am using moleculeRecognize function to upload structures from images and I am attempting to convert the structures in .mol files. However every time I convert to .mol files the hydrogen atoms in the structures are not being accounted for. I was wondering if anyone has any way to overcome this.</p> https://mathematica.stackexchange.com/q/172981 6 Listing all subgroups dharmatech https://mathematica.stackexchange.com/users/527 2018-05-10T19:46:37Z 2022-05-24T13:27:26Z <p>Here's how to show all subgroups of $S_4$ in <a href="https://www.gap-system.org/" rel="noreferrer">GAP</a>:</p> <pre><code>gap&gt; AllSubgroups(SymmetricGroup(4)); [ Group(()), Group([ (1,2)(3,4) ]), Group([ (1,3)(2,4) ]), Group([ (1,4)(2,3) ]), Group([ (3,4) ]), Group([ (2,3) ]), Group([ (2,4) ]), Group([ (1,2) ]), Group([ (1,3) ]), Group([ (1,4) ]), Group([ (2,4,3) ]), Group([ (1,3,2) ]), Group([ (1,4,2) ]), Group([ (1,4,3) ]), Group([ (1,4)(2,3), (1,3)(2,4) ]), Group([ (3,4), (1,2)(3,4) ]), Group([ (1,4), (1,4)(2,3) ]), Group([ (2,4), (1,3)(2,4) ]), Group([ (1,3,2,4), (1,2)(3,4) ]), Group([ (1,4,3,2), (1, 3)(2,4) ]), Group([ (1,2,4,3), (1,4)(2,3) ]), Group([ (3,4), (2,4,3) ]), Group([ (1,4), (1,4,3) ]), Group([ (2,3), (1,3,2) ]), Group([ (1,2), (1,4,2) ]), Group([ (1,4)(2,3), (1,3)(2,4), (3,4) ]), Group([ (1,2) (3,4), (1,3)(2,4), (1,4) ]), Group([ (1,2)(3,4), (1,4)(2,3), (2,4) ]), Group([ (1,4)(2,3), (1,3)(2,4), (2,4,3) ]), Group([ (1,4)(2,3), (1,3)(2,4), (2,4,3), (3,4) ]) ] </code></pre> <p>In Mathematica I can display the elements of $S_4$:</p> <pre><code>In:= GroupElements[SymmetricGroup] Out= {Cycles[{}],Cycles[{{3,4}}],Cycles[{{2,3}}],Cycles[{{2,3,4}}],Cycles[{{2,4,3}}],Cycles[{{2,4}}],Cycles[{{1,2}}],Cycles[{{1,2},{3,4}}],Cycles[{{1,2,3}}],Cycles[{{1,2,3,4}}],Cycles[{{1,2,4,3}}],Cycles[{{1,2,4}}],Cycles[{{1,3,2}}],Cycles[{{1,3,4,2}}],Cycles[{{1,3}}],Cycles[{{1,3,4}}],Cycles[{{1,3},{2,4}}],Cycles[{{1,3,2,4}}],Cycles[{{1,4,3,2}}],Cycles[{{1,4,2}}],Cycles[{{1,4,3}}],Cycles[{{1,4}}],Cycles[{{1,4,2,3}}],Cycles[{{1,4},{2,3}}]} </code></pre> <p>What's a good approach for listing the subgroups in Mathematica?</p> https://mathematica.stackexchange.com/q/42278 5 Non-descending Tuples MMM https://mathematica.stackexchange.com/users/11001 2014-02-14T10:54:06Z 2022-05-24T21:42:40Z <p>I want to get all the non-descending tuples of a list with given length, for example:</p> <pre><code>f[{1,2,3,4},{3}] </code></pre> <blockquote> <pre><code>{{1,1,1},{1,1,2},{1,1,3},{1,1,4},{1,2,2},{1,2,3},{1,2,4},{1,3,3},{1,3,4},{1,4,4}, {2,2,2},……,{4,4,4}} </code></pre> </blockquote> <p>A function lies between <code>Tuples</code> and <code>Subsets</code> to some degree.</p> <p>Is the an efficient way to achieve this? (It should be general for all kind of elements, like <code>Tuples</code>, not specifically for <code>Integers</code>.)</p>