Skip to main content

Posts

Showing posts from 2015

Crash when displaying / rasterizing graphics with textures at high resolutions

CAUTION/Disclaimer: execution of some of the code below can result in a complete crash of Mathematica or even your system. Save all your work and do not try in a productive situation. For a graphical application, I need to export graphics containing several hi-res textures at large image sizes. Consider the following (minimal example) code wich is largely harmless: Graphics[{Texture[Graphics[Circle[]]], Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}, ImageSize -> 400] But upping ImageSize past a given (probably hardware-dependent, in my case ~4000) threshold will crash the frontend+kernel Graphics[{Texture[Graphics[Circle[]]], Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}, ImageSize -> 4000] To make things worse, this also seems to depend on the graphics driver version. I use a NVIDIA GTX 485M card, and with the 296.10 driver, I can go up to abo

plotting - Rasterized density plot with vector axes

I'm wondering if there is an easy way to get the plot below exported in a small PDF file? The plot below is made in the following steps: Create a StreamPlot Create a DensityPlot , where the DensityPlot has to have a lot of sampling points in some cases !! Put the two of them together. Now whenever I save this as a PDF-file it becomes huge due to the large amount of sampling points. Now I was wondering if it was possible to get this in a single (small !!) PDF-file? As far as I understand I need to rasterize the density plot and put the axes separately. Now I've seen some answers regarding this for a ListDensityPlot , but it doesn't seem to work for a DensityPlot . Whenever I try to put the PlotRangePadding to 0 weird things happen. Next to that I've also not been able to put the legend next to the plot after rasterization. Are there any hints on this ? Code to reproduce the above example: vx[x_, y_, d_] := -y*(1/((x - d)^2 + y^2) - 1/((x - 1/d)^2 + y^2)) + y*(1/((x

files and directories - Change Temporary Directory

How to change the value of $TemporaryDirectory ? I need to change it because there is not enough space on the C drive and the calculation seems to stop after a while ! Answer Just set $TemporaryDirectory to a desired directory. You can use system commands such as FileNameJoin or FileNameSetter to create a directory name appropriate to your system. I have a unix-based Mac, so I ran an example using $TemporaryDirectory = "/tmp/math" Here is the example from the docs for OpenWrite , executed under this new setting. Create and open a new stream for writing: fname = FileNameJoin[{$TemporaryDirectory, "testfile"}]; s = OpenWrite[fname] (* OutputStream["/tmp/math/testfile", 145] *) Write an expression to the stream: Write[s, Expand[(x + y)^10]] Close the stream: Close[s] (* "/tmp/math/testfile" *) And so on. Caveat: On my system, the temporary directory used for s = OpenWrite[] (from the docs for $TemporaryDirectory ) is not $TemporaryDirectory ,

list manipulation - Eigenvalues and Eigenvectors Order

Say I have a list of eigenvalues and eigenvectors produced from a matrix $M$ using the command {eig1,eig2}=Eigensystem[M] , which will return the eigenvalues with respective eigenvectors of $M$. I want to now produce a new list list1 which will output a list of eigenvalues and the $L^{\infty}$ norms of the respective eigenvectors. How could this be done? I previously defined Eig1[m_]:=Eigenvalues[m] and Eig2[m_]:=Eigenvectors[m] , then used: EigIf[m_]:=Map[Max[#]&,Eig2[m]] To then obtain the table with {Eig1[m_],EigIf[m_]} . However, I'm not sure if the order in which the eigenvectors are returned with Eigenvectors[m] is respective to the order given by Eigenvalues[m] (so the first eigenvalue in the latter corresponds to the first eigenvector in Eigenvectors[m] ). Can something similar be done with Eigensystem[m] ? Thank you!

list manipulation - Why does MatrixForm affect calculations?

This is a really newbie question, but it has me confused. Why does this code work without // MatrixForm and doesn't work with // MatrixForm ? cov = {{0.02, -0.01}, {-0.01, 0.04}} // MatrixForm W = {w1, w2}; FindMinimum[ W.cov.W, W] The error is: The function value ... is not a real number Is MatrixForm supposed to be typesetting feature or it has other impact? A similar problem appears here: a = {{1, 0, 1, 0}, {2, 1, 1, 1}, {1, 2, 1, 0}, {0, 1, 1, 1}}; inv = Inverse[a]; b = MatrixForm@{{0}, {0}, {0}, {1}}; soln = inv.b Answer MatrixForm is a wrapper that pretty-prints your matrices. When you do the following: cov = {{0.02, -0.01}, {-0.01, 0.04}} // MatrixForm you're assigning the prettified matrix to cov (i.e., wrapped inside a MatrixForm ). This is not accepted as an input by most functions (perhaps all) that take matrix arguments. What you should be doing to actually assign the raw matrix to cov , yet get a pretty print in the output, is the following: (cov = {{0.02,

differential equations - Solve the n ODE in the loop, add the solutions to create one function

I need to solve the n ODE and create a function which is a sum of all the solutions. I wanted to use the code below, but only part ( solve ) and ( create solution ) works well. How can I store the solutions from each ODE and add them together to obtain one function ? Thank you for any help sxf={}; (* list for solutions of each ODE *) For [i = 1; i < 10, i++; xusol = DSolve[{dx[[i]] == a[[i]], x0ui[[i]] == x0u[[i]]}, x[[i]], t] (*solve*) sx[t_]:= Evaluate[x[[i]] /. xusol]; (* create solution ??? *) AppendTo[xlist,sx]; (* store *)] sxf = Function[t, Sum[sx,{i, 1, Ns}]]; (* sum all solutions ??? *) Plot[sxf[t], {t, 0, tmax}] (* plot x[t] *)

function construction - SetAttributes[f,Flat]: Why the order dependence?

I'm experiencing a strange phenomenon. Here's a (quite artificial) test case: The following definition work just fine: f[x___Real]:={x} g[a_,f[n_Integer]]:={a,n} SetAttributes[f,Flat] f[a,f[b,c]] (* --> f[a,b,c] *) g[f[1.0],3] (* --> g[{1.},3] *) As do the following (in a fresh kernel): f[x___Real]:={x} SetAttributes[f,Flat] g[a_,f[n_Integer]]:={a,n} f[a,f[b,c]] (* --> f[a,b,c] *) g[f[1.0],3] (* --> g[{1.},3] *) However, the following (evaluated in a fresh kernel again) hangs on the definition of g : SetAttributes[f,Flat] f[x___Real]:={x} g[a_,f[n_Integer]]:={a,n} Now I don't see any reason why the definition of g should depend on whether I've first defined f or first set the Flat attribute on it. Can anyone explain the mystery? PS: If anyone can think of a better title, feel free to change it accordingly. Answer Ok, I'm going to try to explain my best conjuecture as to how this happens, and don't even try to answer why. There are three reas

plotting - Transformation of values on $x$ and $y$ axis for a LogLogPlot

I have been puzzled by the following issue: When I am using LogLogPlot , while the graph of the function is transformed into the corresponding logarithmic expression, the values on the x and y axes remain the same. A good example is the following, taken from the documentation: LogLogPlot[x^2, {x, 0.1, 10}] When at x=10 the value of x^2 at $y$ axis should be, as correctly shown 100 but at a LogLogPlot , with Log[10,x] it should be: $\text{Log} (10^2)=2 \text{Log} 10=2$. Also, at x=10 the $x$ axis should be equivalently $\text{Log 10} =1$. But none of this is happening. How is it possible to tell Mathematica to show the logarithmic values of the function and not the original ones? Answer A couple of ways: Log-parametric plot: ParametricPlot[Log10@{x, x^2}, {x, 0.1, 10}, AspectRatio -> 0.6] Redefining the ticks (note that LogLogPlot transforms the coordinates by the natural logarithm, so the ticks have to be scaled by Log[10] to get common logarithm coordinate markings): Sh

Is there a more elegant and efficient way to write brainf*** style loops in Mathematica?

I'm having some fun writing a brainf*** interpreter in Mathematica. See this wiki article for more info. It works nicely but I'd like to find an elegant, preferably functional, way to handle the looping structures. This is a simple example of what I'm hoping to do with the solution I currently have in place. The variable ptr is the position of a pointer in the program. The variable paren is used to keep track of the brackets, it increments on "[" and decrements on "]" so it should be zero when I find the proper closing bracket. ptr = 1; paren = 1; lst = {"[", "[", "-", "]", ">", ">", ">", ".", "<", "<", "<", "]", ">", ">", ">", ">", ">", ">", "."}; While[paren > 0, ptr++; Switch[lst[[ptr]], "[", paren++,

symbolic - Define an operator with the distributive property

I would like to define the ⊕ operator with distributive, associative, and commutative properties - so that Mathematica can symbolically simplify expressions I use it in. For example: in := Simplify[a b ⊕ a c] out := a (b ⊕ c) I've already given the ⊕ operator the Flat and Orderless attributes, giving the operator the other two properties I would like, but I can't figure distribution out. Specifically, what I'm trying to do is define an operator which has the symbolic properties of Plus, but which does not evaluate against numbers, e.g in := 2⊕2 out := 2⊕2 is a fully simplified expression.

matrix - While loop (or alternative) to generate list of random submatrices satisfying condition

I'm trying to generate a list of random submatrices with matrix norm 0.1, however I'm getting stuck; currently my code looks like this, where I run over a while loop. Randnum:= RandomReal[NormalDistribution[0, 1]]; Randz := Randnum + I*Randnum; Randmat[n_] := Table[Randz, {n}, {n}]; Randuni[n_] := Orthogonalize[Randmat[n]]; fbfmatricestest={}; tbtmatricestest={}; epsilontest={}; normepsilontest={}; While[Length[normepsilontest]<=1, ( (*Generate a random matrix*) a=Randuni[4]; (*Take the 3x3 submatrix out*) b=Take[a,{1,3},{1,3}]; (*generate the epsilon matrix*) \[Epsilon]=Simplify[ConjugateTranspose[b].b -{{1,0,0},{0,1,0},{0,0,1}}]; (*n\[Epsilon] measures gives the norm of each submatrix*) n\[Epsilon]=Norm[\[Epsilon]]; If[ Abs[n\[Epsilon]-0.1]<0.01, ( AppendTo[fbfmatricestest,a]; AppendTo[tbtmatricestest,b]; AppendTo[epsilontest,\[Epsilon]];

output formatting - Can one prevent operators like `Factor` or `Apart` from changing full form of some algebraic expressions?

In this question I will talk about a toy example, it should be clear what do I actually mean in general. Also, not only Factor but also Apart and several other important operators have this behavior. Say, Factor[1/(1 - t)] produces -(1/(-1 + t)) which is not just formatting but full form change: FullForm[1/(1 - t)] is Power[Plus[1,Times[-1,t]],-1] while FullForm[Factor[1/(1 - t)]] gives Times[-1,Power[Plus[-1,t],-1]] which I find sort of inconvenient sometimes. Not that I care about internals of representing objects, most probably it is optimized in some way, but when I need to work with such expressions, introduction of redundant extra minus signs, etc. is which I find inconvenient. What would be the correct way to deal with this? One related question I found is How to put terms in lexicographic order? where one of possibilities named was to issue $PrePrint = PolynomialForm[#, TraditionalOrder -> True] &; but some adverse effects of it were also mentioned. And in fact, T

plotting - Getting a correct custom legend for contourplot?

I am having trouble making a custom range for a legend in ContourPlot since the legend doesn't "talk" to the PlotRange and adjust its scale accordingly. How do I go about fixing this? As an explicit example consider the following. If I run ContourPlot with an automatic legend I get the right scaling: ContourPlot[x y , {x, 0, 2}, {y, 0, 2}, PlotLegends->Automatic, ColorFunction ->"BlueGreenYellow"] But if I use a custom legend range then the legend no longer corresponds to the image: ContourPlot[x y , {x, 0, 2}, {y, 0, 2}, PlotLegends -> BarLegend[{"BlueGreenYellow", {0, 10}}] How do I get the plot to use the same scale as the legend? Answer This was more involved than I expected. First, you need to set the ColorFunction to encompass the full range, ColorData[{"BlueGreenYellow", {0, 10}}] Interestingly, I did not know about that form of ColorData until earlier this week, so I recommend reading through the Details section clos

Simplify a Boolean Algebra expression with don't cares

I want to simplify this expression: BooleanMinimize[(A ∧ ¬ B ∧ C ∧ ¬ D) ∨ (A ∧ B ∧ ¬ C ∧ ¬ D) ∨ (A ∧ B ∧ C ∧ ¬ D)] And I get this: (A ∧ B ∧ ¬ D) ∨ (A ∧ C ∧ ¬ D) But using a Karnaugh Map and "don't cares" I get ¬ D . Is there anyway that I can get similar answer in Mathematica ? Answer An arbitrary function with "don't cares" can be defined using either BooleanFunction or BooleanConvert , but in those cases, Mathematica makes no effort to find the minimal representation of such a function. Instead, use BooleanMinimize with the optional third argument: an assumed condition on the variables. In your case, you can specify that your "don't cares" are 0-9 by making the condition be A ∧ (B ∨ C) . Then the calculation BooleanMinimize[ (A ∧ ¬ B ∧ C ∧ ¬ D) ∨ (A ∧ B ∧ ¬ C ∧ ¬ D) ∨ (A ∧ B ∧ C ∧ ¬ D), "DNF", A ∧ (B ∨ C)] will produce the desired output of !D .

front end - How to let output and message be print to two separate external files?

How to let output and message be print to two separate external files? Also, I'd like the content print out to have similar look as when it's print inside the notebook, i.e. it should be in OutputForm or whatever proper form. Answer Sounds like you are looking for $Messages and $Output , and maybe also $PrePrint or $Post . $Messages and $Output are a list of streams to which corresponding output is written (note that $Output is only getting output from Print s, not from return values of shift-return-evaluations). To cover return values of shift-return-evaluations you might want to manipulate $PrePrint or $Post so it will also write to the desired output file. You can open a file for each with OpenWrite and append the resulting streams to the two lists and the messages and output will be written to those files. You can use the option FormatType of OpenWrite to write to those files in OutputForm . But since these are text files the outcome is not very useful in my opi

computational geometry - Finding non-collinear vertices of a convex hull

I'm fairly new to Mathematica (and programming in general tbh) and need this for a math project I'm working on. I generate large collections of (rational, 2d) points and need to find which of these points are the vertices of the convex hull. Some googling suggested that MeshCoordinates would do this, but it does not exclude points on the edges of the convex hull that are collinear with the vertices. It also gives rounded decimals but that is less of an issue. Is there a simple way to do this? Edit to include a simplified example, the vertices of the unit square with a redundant point ( {1, .5} ): pts = {{0, 0}, {1, 0}, {0, 1}, {1, 1}, {1, .5}} Both MeshCoordinates[ConvexHullMesh[pts]] and ConvexHullMesh[pts]["VertexCoordinates"] return the point {1, .5} , which is clearly not a vertex of the unit square. The points I'm generating are not random, they are the result of a fairly involved set of calculations and many of them can be collinear. Answer Update: a

performance tuning - Considerations when determining efficiency of Mathematica code

I have two segments of code that do the same thing and I want to determine the which is more efficient. What are the considerations when determining efficiency of Mathematica code? Correctness/Equality of code segments AbsoluteTiming vs Timing ... Why? Clearing the cache Memory footprint (speed vs size) ... Any suggestions on how to measure this? More? Any useful packages out there to assist in this? Hypothetical Code Segment 1 numbers = {}; For[i = 0, i < 100, i++, AppendTo[numbers, i]]; numbers Hypothetical Code Segment 2 Range[0, 99] Testing Code (* Test Equality *) Print["Equality: ", numbers = {}; For[i = 0, i < 100, i++, AppendTo[numbers, i]]; numbers == Range[0, 99]] (* Timing Comparison *) iterations = 10000; times = Map[{ AbsoluteTiming[ numbers = {}; For[i = 0, i < 100, i++, AppendTo[numbers, i]]; numbers ][[1]], AbsoluteTiming[ Range[0, 99] ][[1]] } &, Range[1, iterations]]; {times1, times2} = Tran

plotting - ErrorListPlot - Problem with PlotRange

Bug introduced in 10.4 or earlier and persisting through 12.0 Consider the following example: ClearAll["Global`*"]; Needs["ErrorBarPlots`"]; x=Table[n,{n,1,100}]; SeedRandom[314]; y=RandomReal[{9,10},100]; yErr=RandomReal[{0,1},100]; yWithErrors=Transpose[{Transpose[{x,y}],ErrorBar/@yErr}]; ErrorListPlot[yWithErrors, Joined -> True, PlotStyle -> {Blue}, Epilog -> {PointSize[Large], Point[Transpose[{x, y}]]}, PlotRange -> All, Frame -> True, FrameLabel -> {{"y", ""}, {"x", ""}}, BaseStyle -> {FontSize -> 20, FontFamily -> "Calibri"}, ImageSize -> 600] Independently if I use PlotRange -> All , PlotRange -> Total or PlotRange -> Automatic the output is: As you see the error bars are not completely visible. Is the only solution to see the error bars to set the PlotRange manually? ErrorListPlot[yWithErrors, Joined -> True, PlotStyle -> {Blue}, Epilog -> {PointSize[L

How to make Huffman coding by using tree representation

I want to make Huffman coding with Mathematica. I saw a demonstration , but it is not the thing I want to make. I want to show the tree for given string. Here is an example picture: You can see the demonstration from here . This demonstration looks very atractive but difficult. However, I believe at least, making step by step should be possible.

The correct pattern for Cases

I have a problem that, admittedly, I have already solved using Select instead, but it is irking me that I cannot seem to construct the right pattern to solve it using Cases . I would like the output of Cases[ {{{1, 2}, {3}, {4, 5}}, {{6}, {}}, {{}, {}}}, (* THE CORRECT PATTERN HERE *) ] to be {{{1, 2}, {3}, {4, 5}}, {{6}, {}}} In other words, I would like a pattern that picks up all the elements of the outer list that have at least one non-empty list as an element. Thanks in advance for your help. Answer list = {{{1, 2}, {3}, {4, 5}}, {{6}, {}}, {{}, {}}}; Cases[list, Except[{{} ..}]] (* {{{1, 2}, {3}, {4, 5}}, {{6}, {}}} *) or Cases[list, {___, Except[{}], ___}] (* {{{1, 2}, {3}, {4, 5}}, {{6}, {}}} *) You can also use PatternTest ( _?func ) where func is any selector function that you might have used as the second argument of Select . For example: Select[list, Union @@ # =!= {} &] (* or Flatten @ # =!= {} & or ... *) (* {{{1, 2}, {3}, {4, 5}}, {{6}, {}}} *) Ca

plotting - Problem with PlotLabels

Bug introduced in 10.4, fixed in 11.0. Version 10.4 introduced the PlotLabels option in ListPlot and similar functions. But it seems that it doesn't work when setting the PlotRange . For example ListLinePlot[{1, 1, 2, 3, 5, 8}, PlotRange -> {All, {5.5, 6}}, PlotLabels -> 1] Could you confirm it as a bug? I'm using version 10.4 on OS X 10.11.4.

programming - How to implement Kemeny-Young method? (rank aggregation problem)

Prehistory I am trying to make some statistical analysis of some experimental data, arises from measurements made ​​on an ordinal scale. I faced with the problem of rank aggregation : to get from many "individuals" orderings (on the same set of objects) one "collective" ordering. The most "natural" approach to this problem is Kemeny-Young method (better look primary source ). Surprisingly I found out that there is no program application for this method!!! (There is one C++ code , but it does not allow weak orderings, i.e., does not allow cases when several objects share same position at ordering). Previously I asked some points ( one , two ) for constructing needed code, but now I have decide to tell all at once — because the problem is more complicated than I thought at first, and I can miss some points since I am null in Mathematica and programming. Description Let $R_1, R_2, R_3, ..., R_N$ denote "individuals" weak orderings of $N$ given obj

calculus and analysis - Why the Kernel crashes on these integrals in V12?

Reported to WRI, [ CASE:4331819 ] This is using V12, on windows 10, 64 bit. Note: these integrals work OK on 11.3 on same PC. Any idea why the Kernel now crashes on these types of integrals? ClearAll[x,a,b,c,e,d,f,g,n]; (*these from file #40,41*) Integrate[(1 + x^2)^3/(1 + x^2 + x^4)^(3/2), x]; Integrate[(1 + x^2)^2/(1 + x^2 + x^4)^(3/2), x]; Integrate[(1 + x^2)/(1 + x^2 + x^4)^(3/2), x]; Integrate[(7 + 5*x^2)^3/(2 + 3*x^2 + x^4)^(3/2), x]; Integrate[(7 + 5*x^2)^2/(2 + 3*x^2 + x^4)^(3/2), x]; Integrate[(7 + 5*x^2)/(2 + 3*x^2 + x^4)^(3/2), x]; Integrate[(2 + 3*x^2 + x^4)^(3/2)*(7 + 5*x^2)^3, x]; Integrate[(2 + 3*x^2 + x^4)^(3/2)*(7 + 5*x^2)^2, x]; Integrate[(2 + 3*x^2 + x^4)^(3/2)*(7 + 5*x^2), x]; Integrate[(7+5*x^2)^4/(2+3*x^2+x^4)^(3/2),x]; Integrate[(7+5*x^2)^2/(2+3*x^2+x^4)^(3/2),x]; Integrate[(4+3*x^2+x^4)^(3/2)*(7+5*x^2),x]; Integrate[(d+e*x^2)*(a+b*x^2+c*x^4)^(3/2)/(f*x)^(1/2),x]; (*these from file #42*) Integrate[(a*g - c*g*x^4)/(a + b*x^2 + c*x^4)^(3/2), x]; Integrate[(a*g+e*x-

geography - plotting a {{Latitude,Longitude}} list on top of a GIS shapefile

I have a dataset composed of points specified in {Latitude,Longitude} format. Call it latlong for the purposes of this question. It displays properly with Graphics[{Point /@ Map[GeoGridPosition[GeoPosition[#], "Mercator"][[1]] &, {latlong}, {2}]}] I also have a shape file that contains the boundaries of the counties in which the latlong points reside. If I query Import[demo.shp", "CoordinateSystemInformation"] , I get "GEOGCS" -> {"GCS_North_American_1983", "DATUM" -> {"North_American_Datum_1983", "SPHEROID" -> {"GRS_1980", 6.37814*10^6, 298.257}}, "PRIMEM" -> {"Greenwich", 0.}, "UNIT" -> {"Degree", 0.0174533}} and if I just Import the shape file, it displays correctly on screen. I would like to display the points from latlong within the county borders from demo.shp . I have not been able to figure out how. I appreciate th

plotting - How does one get Mesh lines at 0 in ParametricPlot3D?

The following is in the documentation (MMA 10) under ParametricPlot3D -> Options -> Mesh : ParametricPlot3D[{(2 + Cos[v]) Cos[u], (2 + Cos[v]) Sin[u], Sin[v]}, {u, 0, 2 Pi}, {v, 0, 2 Pi}, Mesh -> 10] You'll see that the lines for u=0 and for v=0 are missing. These can be restored by using Mesh->Full , but then the number of lines will be the default, 15. I'd also like to have the number of lines be different in the two directions, with each one containing 0, but Mesh->{Full,10}, e.g., gives an error. Here is the image in the documentation: Update: While the answer below works as requested, it does not work for tubes. See this example: ParametricPlot3D[{(2 + Cos[v]) Cos[u], (2 + Cos[v]) Sin[u], Sin[v]}, {u, 0, 2 Pi}, {v, 0, 2 Pi}, Mesh -> 10, BoundaryStyle -> Tube[.03], MeshStyle -> Tube[.03]] Answer You need to use BoundaryStyle -> ... (because 0 lies at the boundary of u and v ranges: ParametricPlot3D[{(2 + Cos[v]) Cos[u], (2 + Cos[v]) Si

calculus and analysis - Solve command does not solve this equation!

I tried to solve the following equation with Mathematica: $\left(1-x^2\right) \left(n \left(x^4-2 x^2+5\right)-4 \pi \left(x^2-1\right)\right) \sinh (\pi x) \cosh (n x)+\sinh (n x) \left(\left(1-x^2\right) \left(\pi \left(x^4-2 x^2+5\right)-4 n \left(x^2-1\right)\right) \cosh (\pi x)-2 x \left(x^4-2 x^2-3\right) \sinh (\pi x)\right)=0$ but the answer is: "This system cannot be solved with the methods available to Solve." I also tried Maple, the result was a long relation in terms of RootOf. How can I obtain an explicit solution for $x$ in terms of $n$ ? (1/(4 (-1 + x^2)^2))((1 - x^2) (-4 \[Pi] (-1 + x^2) + n (5 - 2 x^2 + x^4)) Cosh[n x] Sinh[\[Pi] x] + Sinh[n x] ((1 - x^2) (-4 n (-1 + x^2) + \[Pi] (5 - 2 x^2 + x^4)) Cosh[\[Pi] x] - 2 x (-3 - 2 x^2 + x^4) Sinh[\[Pi] x])) == 0 Answer As I noted in my answer to your other question, this type of problem can be solved numerically using FindAllCrossings from this answer. With[ {n = 1},

associations - Manipulating unevaluated expressions in nested function calls

This is a follow-up to my earlier question: Passing an unevaluated part of an association to a function I'm trying to create a modular dashboard that controls sound volume of an audio system consisting of several speakers. System settings are given by the following association: speakers = <| "speaker1" -> <|"volume" -> 0.5|>, "speaker2" -> <|"volume" -> 0.7|> |> I have a simple widget AdjustOneSpeaker that takes in a part of the speakers variable corresponding to one of the speakers, and dynamically adjusts its volume using a slider: SetAttributes[AdjustOneSpeaker, HoldAll]; AdjustOneSpeaker[speaker_] := { Slider[Dynamic[speaker["volume"]]], Dynamic[speaker["volume"]] }; Passing speakers["speaker1"] to this widget works fine: AdjustOneSpeaker[speakers["speaker1"]] To use AdjustOneSpeaker function as a building block for a composite dashboard, I must be abl

accuracy - SetAccuracy behavior

I'm puzzled by the output I get from SetAccuracy . According to the documentation, when SetAccuracy is used to increase the accuracy of a number, the number is padded with zeros. But, let's take a look at a couple of examples: SetAccuracy[1.2, 5] (* 1.2000 *) SetAccuracy[1., 5] (* 1.0000 *) SetAccuracy[0.2, 5] (* 0.2000 *) These examples seem to work properly, so why does it behave differently in this case? SetAccuracy[0., 5] (* 0.*10^-5 *) What should I do to get a zero with four trailing zeros? Update I'm asking this question, because I need to export data to a txt file and I would like to avoid having 0.*10^-5 sort of numbers. Answer The comments by image_doctor led me to the answer I was looking for: StandardForm@NumberForm[1.2, {20, 4}, ExponentFunction -> (Null &)] (* 1.2000 *) StandardForm@NumberForm[1., {20, 4}, ExponentFunction -> (Null &)] (* 1.0000 *) StandardForm@NumberForm[0.2, {20, 4}, ExponentFunction -> (Null &)] (* 0.2000 *) Standa

graphics - Mollweide maps in Mathematica

Context In my field of research, many people use the following package: healpix (for Hierarchical Equal Area isoLatitude Pixelization) which has been ported to a few different languages (F90, C,C++, Octave, Python, IDL, MATLAB, Yorick, to name a few). It is used to operate on the sphere and its tangent space and implements amongst other things fast (possibly spinned) harmonic transform, equal area sampling, etc. In the long run, I feel it would be useful for our community to be able to have this functionality as well. As a starting point, I am interested in producing Mollweide maps in Mathematica. My purpose is to be able to do maps such as which (for those interested) represents our Milky Way (in purple) on top of the the cosmic microwave background (in red, the afterglow of the Big Bang) seen by the Planck satellite . Attempt Thanks to halirutan's head start, this is what I have so far: cart[{lambda_, phi_}] := With[{theta = fc[phi]}, {2 /Pi*lambda Cos[theta], Sin[theta]}] fc[p