Skip to main content

Posts

plotting - What is the fundamental difference between "PlotPoints" and "MaxRecursion"?

When making a plot, PlotPoints or MaxRecursion options are used to specify the accuracy or the extent of how detailed the result will be. Ff either of them do the similar job, I think only one option of the two is enough for the purpose. Then, why the two are used in Mathematica? What is the fundamental difference between them? Answer PlotPoints guarantees a number of points that will be plotted. MaxRecursion states the maximum recursion, which might not be needed or used in a given plot. If I'm plotting a large number of functions—some simple, some complex—then I use MaxRecursion so as to speed the plotting of "simple" graphs. Moreover, PlotPoints generally places the points equally spaced while MaxRecursion effectively places the extra detail in positions of the plot with rapidly changing function, as is evident in the small-$x$ values in the graph: Plot[Sin[1/x], {x, 0, 1}] .

equation solving - Solve `f(x)=0` with a parameter

I want to solve f(x)=0 with following code (with a parameter): $Assumptions = \[Lambda] > 0; f[x_] := x - \[Lambda]*Cosh[x/4]; FindRoot[f[x] == 0, {x, 0}] N[FindInstance[f[x] == 0, x, Reals, 2]] N[Reduce[f[x] == 0, x, Reals]] NSolve[f[x] == 0, x, Reals] N[Solve[f[x] == 0, x, Reals]] But I do not have any solution. I can solve f(x)=0 for following code (without parameter): f[x_] := x - Cosh[x/4]; FindRoot[f[x] == 0, {x, 0}] N[FindInstance[f[x] == 0, x, Reals, 2]] N[Reduce[f[x] == 0, x, Reals]] NSolve[f[x] == 0, x, Reals] N[Solve[f[x] == 0, x, Reals]] Any suggestions?

computational geometry - How to find the vertices of a regular tetrahedron? a dodecahedron?

My question is: how to find the coordinates of the vertices of regular tetrahedron and dodecahedron ? I tried to find the coordinates of the vertices of a regular tetrahedron as the solutions of a certain polynomial system in $8$ variables, notating the vertices of a tetrahedron $S(0,0,1)$, $A(0,yA,zA)$, $B(xB,yB,zB)$, and $C(xC,yC,zC)$: Reduce[ yA^2 + zA^2 == 1 && xB^2 + yB^2 + zB^2 == 1 && xC^2 + yC^2 + zC^2 == 1 && yA^2 + (zA - 1)^2 == xB^2 + yB^2 + (zB - 1)^2 && yA^2 + (zA - 1)^2 == xC^2 + yC^2 + (zC - 1)^2 && xB^2 + (yB - yA)^2 + (zB - zA)^2 == xC^2 + (yC - yA)^2 + (zC - zA)^2 && xB^2 + (yB - yA)^2 + (zB - zA)^2 == (xC - xB)^2 + (yC -yB)^2 + (zC - zB)^2 && xB^2 + (yB - yA)^2 + (zB - zA)^2 == yA^2 + (zA - 1)^2, {xB, xC, yA, yB, yC, zA, zB, zC}, Reals] However, that code is spinning for hours without any output. A new idea is required. P.S. 12.12.13. The answer done wi...

programming - ++ is dangerous for C programmers

I noticed this fact, that may be misleading for programmers used to C language. In Mathematica , if you have a function f[] and an array v , and you write v[[ f[] ]]++ the function f is called twice. Probably experts knows this very well, but I used MMA for years ignoring this. Normally this behaviour is harmless, but this should be taken into account if f is costly, has side-effects or can return different values based on the same input. Indeed, I realized this property of ++ because of this: t={0,0,0}; r[]:=RandomInteger[{1,3}]; Do[t[[r[]]]++,{10000}]; Print[t," ",Total[t]] where I increment a random entry of t 10000 times, but at the end the sum of entries of t is not 10000. This is insidious for C programmers, because in C if you write a similar code v[f()]++ , the function f() is called just once. I would like to ask if this semantic of ++ is somehow "forced" by the overall structure of Mathematica language or if they could have implemented it differen...

functions - Strange Integrate behavior (a bug!)

The following two calculations should give the same result. After all, integration is a linear operation. I have pasted the code below in case you want to play with it. Integrate[Integrate[v[x], x] - Integrate[Integrate[v[x], x] * u'[x], x]/u[x], x] Integrate[Integrate[v[x], x], x] - Integrate[Integrate[Integrate[v[x], x] * u'[x], x]/u[x], x]

export - LF line break instead of CR+LF when exporting text files on Windows

I want my program to always save a text file with unix-style LF line breaks (even when Mathematica runs on Windows). But the way the built-in Export command works depends on the operating system. For example the following code: testFile = "newlinetest.txt"; testStringList = {"abc", "abc"}; Export[testFile, testStringList, "List"]; BinaryReadList[testFile] Linux or Mac OS gives exactly what I want: {97, 98, 99, 10, 97, 98, 99} Windows adds an extra CR symbol: {97, 98, 99, 13 , 10, 97, 98, 99} Is there a normal way to save text files with unix-style newline on Windows?

recursion - Model-checking with Mathematica. Comparison of recursive functions where argument is unknown function

I would like to try some model-checking with recursive functions. The way it can be programmed with Mathematica (from my perspective) is following: S1[0,a_]=0 S1[t_,a_]:=S1[t-1,a]+1/; a[t-1] S1[t_,a_]:=0/; !a[t-1] S2[0,a_]=0 S2[t_,a_]:=S2[t-1,a]+2/; a[t-1] S2[t_,a_]:=0/; !a[t-1] S1[t,port]==2*S2[t,port] Functions S1 and S2 get two arguments; time -- integer value and port function -- a function that takes time and returns a Boolean value. Note, that function port[t] , that returns Boolean value, is not known beforehand. But the value of S1 and S2 depend on the port value from the previous moment of time ( a[t-1] ). I guess that comparison must be done symbolically after unfolding the S1[t] and S2[t] functions. Since what I have so far is a pretty much pseudo code, I would like to ask what would be the best way to do so, if it is possible at all with Mathematica. Every tip is highly appreciated. Thanks very much in advance.