Skip to main content

Posts

Showing posts from July, 2014

remote kernel through SSH

Is it possible to setup connection to remote kernels through ssh? I'm able to SSH into the remote server(linux) and start a kernel in the terminal, but it can't connect back to my local front end. I asked the network administrator and he says that the "stringent firewall rules" allow only SSH connection to the linux server. So is it possible to setup the connection through SSH? I have seen several solutions here or there but I'm never able to make them work. Could you give a detailed step by step guide? Answer Here's a solution that works quite well with me and a colleague of mine in my research group. I assume you have Mathematica installed on both your local and remote machine. The command MathKernel has to be available on the shell of the remote machine. Short answer : 1- Install GOW if you're using Windows 2- Open command prompt, and connect to the target machine using ssh, command is: ssh hostname . Confirm and make sure the shell is accessible. T

plotting - Customizing DensityPlot[]'s automatic bar legend

To get the density plot of a function f[x,y] with a bar legend, I'm using DensityPlot[f[x,y],{x,0,2 π},{y,0,2 π},PlotLegends -> Automatic] I'm using LinTicks[] of SciDraw to have the axes ticks in units of pi. I would also like to customize the ticks in the bar legend to change in units of pi. There are some questions ( 29643 , 55150 ) here that are trying to solve this problem, but in order to use BarLegend[] one needs to know the range of the function being plotted. For the function I'm plotting, the range is not easy to get analytically. Using a somewhat brute-force approach, I can sample f[x,y] and get the min/max to use with BarLegend[] , but I'm looking for a more elegant approach to this. How can I solve this problem? Thanks! Answer One can use a pure function to specify the ticks of a BarLegend . f[x_, y_] := Sin[1 + x] + 2 Sin[y] + x DensityPlot[f[x, y], {x, 0, 2 π}, {y, 0, 2 π}, PlotLegends -> BarLegend[Automatic, Ticks

list manipulation - How to blend some colors on a curve

I need to define a color gradient on a 3D curve, but I'm having some problems with this. Suppose we have a 3D curve defined as a parametric function of some real variable phi : curve[phi_] := {...}; where phi runs from phi1 to phi2 . Now, I defined the start , middle and end colors like this : Color1 := RGBColor[0.99, 0.2, 0.2, 0.2]; Color2 := RGBColor[0.2, 0.99, 0.2, 0.8]; Color3 := RGBColor[0.2, 0.2, 0.99, 0.2]; CurveColor[phi_] = Blend[{Color1, Color2, Color3}, phi]; The last definition doesn't work. I need the function CurveColor[phi] to output four real positive numbers smaller than 1 , like this : CurveColor[phi1] := {0.99, 0.2, 0.2, 0.2} CurveColor[phi2] := {0.2, 0.2, 0.99, 0.2} The colors should blend smoothly between Color1 to Color2 to Color3 , and be uniformly distributed along the interval phi1 to phi2 ). So how should I define that color function ? I don't need that function to be used in a plot3D. I only need the color data as a list of numbers. Ple

Generate cyclic list from a list

Given a list (for example, {3, 5} ) I would like to make a function genCyclic[n_, list_] which generates a cyclic patterns of list with length n , such that genCyclic[5, {3, 5}] returns {3, 5, 3, 5, 3} or genCyclic[1, {3, 5}] returns {3} . My current solution is to use ConstantArray to generate the full cycle parts ( {3, 5, 3, 5} in the first example) and append the remaining part ( {3} ) and then Flatten them. I have to say my method seems too ugly. In my old memory, which is frequently wrong, though, I thought there was a built-in function with this functionality. After spending some time trying to find such a function and failing, I ended up here. No matter whether there is a built-in function or not, what is the most natural way to implement genCyclic ? Answer Yes there is something quite strightforward: genCyclic[n_, list_] := PadRight[{}, n, list]

front end - Magnification, ScreenResolution, ScreenInformation and Printing: Please shine some Light into it!

According to How to set default magnification for all windows Mathematica assumes 72 dpi screen resolution. In my computer, the screen resolution actually is 120 dpi which is a very common value on recent laptops. Since I worry about different appearance on the screen and on printed notebooks, characters on the screen being too small, strange things happening when editing, sometimes the cursor operates one character left of where it is displayed, which really makes headache! using paragraphs with a negative indent and wanting to use a tab to outdent the first word of such a paragraph I got the idea, to set the screen resolution to 120 dpi which is very close to what my screen really has (it has 120.4 dpi, but I can't enter a decimal number here). I used OptionInspector this way: . The original value in this place was 72. Probably It might haven been the same as executing SetOptions[$FrontEnd, FontProperties->{"AutoSpaceWidth"->{0.221`,0.439`},

plotting - How can I extract trace points from an oscilloscope image?

I have the following oscilloscope image: I would like to extract the points of the yellow curve together with the correct values. Do you know how I could do it? Extracting the yellow curve from the background seems quite difficult to me. Answer Here I trim manually, but you could use Image[MorphologicalComponents[img] and detect the bounding box instead (actually, that's how I found 57 and 455 ). img = Import["https://i.stack.imgur.com/NYfVj.png"] pt1 = {12, 57}; pt2 = {600, 455}; imgCurve = ImageTrim[Image[MorphologicalComponents[img2]], {pt1, pt2}] imgGrid = ImageTrim[Image[MorphologicalComponents[img]], {pt1, pt2}] - imgCurve Then it's not difficult to get the points: data1 = ImageData[Binarize@imgCurve]; points = Reverse /@ Position[data1, 1]; points[[All, 2]] = 520 - points[[All, 2]]; ListPlot@points If you understand this, then you can extract the width and height of the grid, and scale the points accordingly.

equation solving - Q: Problem - FullSimplify returns 0, FindRoot returns value & FindInstance requires system abend

The function at issue: fa[a_] = 99999.99999999999` (-426.3417145941241` + 2.25` a - 2.25` a Erf[ 99999.99999999999` (0.4299932790728411` - 0.18257418583505533` Log[a])] + 23.714825526419478` Erf[ 99999.99999999999` (0.42999327934670234` - 0.18257418583505533` Log[a])]) + 9.999999999999998`*^9 a^3.1402269146507883`*^9 E^( 9.999999999999998`*^9 (-0.36978844033114555` - 0.06666666666666667` Log[a]^2)) (a E^( 1.8749999999999996`*^10 (0.3140226915650789` - 0.13333333333333333` Log[a])^2) (0.24259772920294995` - 0.10300645387285048` Log[a]) + E^(1.8749999999999996`*^10 (-0.3140226913650789` + 0.13333333333333333` Log[a])^2) (-2.556961252217486` + 1.085680036306589` Log[a])); Build and plot the function - show it is not always zero and there is one root. dataa = {#, fa[#]} & /@ Range[1, 1000, 10]; imagea = Plot[fa[a], {a, 0, 400}, Epilog -> {Red, PointSize[0.005], Point[d

plotting - Create a nonlinear color function

I'm doing density plots in Mathematica where I mostly plot Wigner functions . The main objective when plotting a Wigner function is to demonstrate that the underlying state is nonclassical, as indicated by negative values in the Wigner function. Therefore I want to make these negative values stand out in the plot. To demonstrate this, I've plotted the Wigner function of an even cat state which was generated using the following code (* Plots the Wigner function of an even Cat State *) α = Sqrt[ 16]; Wigner[x_, y_] := 1/(π Sqrt[ 1 + Exp[-2 α^2]]) (Exp[-2 (x - α)^2 - 2 y^2] + Exp[-2 (x + α)^2 - 2 y^2] + 2 Exp[-2 x^2 - 2 y^2]*Cos[4 y α]); DensityPlot[Wigner[x, y], {x, -6, 6}, {y, -2, 2}, PlotRange -> All, ColorFunction -> "LightTemperatureMap", PlotLegends -> Placed[ BarLegend[ {"LightTemperatureMap", {-.5, .5}}, LegendMargins -> {{26, 20}, {-15, 0}}, LegendMarkerSize -> {475, 30}], Ab

syntax - Error when using rule as a list index - { i, x[[i]] } /. i -> 5

I can't seem to use a rule to index a vector. x = Range[10]; { i, x[[i]] } /. i -> 5 I get the following error when evaluating the above code, even if the next cell shows the correct result: Part::pspec: Part specification i is neither an integer nor a list of integers. Answer Using Trace , Trace[x = Range[10]; { i, x[[i]] } /. i -> 5] we will see that the error comes from Mathematica trying to evaluate {1,2,3,4,5,6,7,8,9,10}[[i]] As you pointed out, the error message is harmless in this case. If you want Mathematica to substitute first, you can use Hold and ReleaseHold : x = Range[10]; ReleaseHold[Hold[{i, x[[i]]}] /. i -> 5] which prevents the evaluation of {i, x[[i]]} until the Hold is released. The output is the same, but now without the error message: {5,5}

differential equations - Plotting the orbit of the Earth around the Sun. Error: step size is effectively zero; singularity or stiff system suspected

I've been asked to plot the orbit of the Earth around the sun over a period of three years. I've copied my exact code below. When I try to run it I get a series of errors, the first being: NDSolve::ndsz: At t == 9.641612453331499 *^-11`, step size is effectively zero; singularity or stiff system suspected. I'm fairly new to Mathematica and I'm not sure why this error is appearing, or, when an error does appear, how to correct my code given what the error tells me. G = 6.6723*10^(-11); mSun = 1.989*10^30; solEarth1 = NDSolve[{r''[t] == -G*mSun*r[t]/Norm[r[t]]^3, r[0] == {1, 0}, r'[0] == {0, 29785.1}}, r, {t, 0, 94608000}][[1]]; ParametricPlot[r[t] /. solEarth1, {t, 0, 94608000}, AxesLabel -> {"x (m)", "y (m)"}, PlotLabel -> "Orbit of Earth around the Sun"]

bugs - The unexpected behavior of region calculate

Bug introduce in version 10 and presist in 11.2 In my this answer ,I get some overlapped disk like this placed with red arrow point out But actually that function of diskMake is designed to produce nonoverlapping disk.And I don't think I write a wrong code. :) For this question I have some digs like following: wordRegion = BoundaryDiscretizeGraphics[ Text[Style["21", FontFamily -> "Arial"]], _Text]; disks = {Disk[{-2.4107273705611387`, 3.2155412094306577`}, 0.10357806335605606`], Disk[{-1.4610266485101935`, -0.1848766412849958`}, 0.1371293137456506`], Disk[{3.9597015795674757`, -2.0248306466733403`}, 0.21070473733708972`], Disk[{-1.4133143443551681`, -0.5609218789129127`}, 0.2141073441827654`], Disk[{3.4232452614725304`, 1.1487829210947051`}, 0.062352195066279315`]}; disk = Fold[RegionDifference, wordRegion, BoundaryDiscretizeRegion /@ disks]; r = .3;(*You can change the value to 0.3 or 0.6*) Row[Magnify[#, 5] & /@

random - Simulating Theatre puzzle

I have been trying to simulate the process of the theatre puzzle from the Joy of X (Strogatz). The puzzle, and some relevant material are here . My simplistic coding for this process follows: seatchoice[u_] := Module[{r, s}, r = RandomReal[]; s = RandomChoice[u]; If[And[MemberQ[u, s + 1], MemberQ[u, s - 1]], If[r <= 0.5, Complement[u, {s, s + 1}],Complement[u, {s - 1, s}]], If[MemberQ[u, s + 1], Complement[u, {s, s + 1}], If[MemberQ[u, s - 1], Complement[u, {s - 1, s}], If[And @@ (# >= 2 & /@ Differences[Sort[u]]), u, If[Length[u] == 0, u, seatchoice[u]]]]]]]; emptyfraction[v_] := N@Length[FixedPoint[seatchoice, Range[v]]]/v; I have consistently found despite simulations for 100, 1000,2000 seats (recursion and iteration limits are exceeded for large inputs) that expectations are consistently approx 0.124 (versus expected approx 0.135) with narrowing bounds with increasing sample size or sample number. Further, the closed form

simplifying expressions - Simplify rules with variable number of arguments

Problem How to simplify the following rules? The rules simplify (single, double, triple ...) summations of Kronecker delta. Replacement should occur if any summation and the Kronecker delta share an index. The rules Single summation: expr /. Sum[y_ KroneckerDelta[r_, s_], {s1_, 1, p1_}] :> (y /. s1 -> r) Double summation: expr /. Sum[y_ KroneckerDelta[r_, s_], {s1_, 1, p1_}, {s2_, 1, p2_}] :> Sum[(y /. s1 -> r), {s2, 1, p2}] Tripple summation: Sum[y_ KroneckerDelta[r_, s_], {s1_, 1, p1_}, {s2_, 1, p2_}, {s3_, 1, p3_}] :> Sum[(y /. s1 -> r), {s2, 1, p2}, {s3_, 1, p3_}] Test Case expr0 = Sum[Log[Sum[A[j, k, l]*B[j, k, l], {l, 1, L}]], {j, 1, J}, {k, 1, K}] expr = Simplify[D[expr0, A[a, b, c]]] expr = expr /. Sum[y_ KroneckerDelta[r_, s_], {s_, 1, p_}] :> (y /. s -> r) expr = expr /. Sum[y_ KroneckerDelta[r_, s_], {s1_, 1, p1_}, {s2_, 1, p2_}] :> Sum[(y /. s1 -> r), {s2, 1, p2}] expr = expr /. Sum[y_ KroneckerDelta[

plotting - Wrapping a rectangle to form a cylinder

I'd like to make an animation showing how we wrap a rectangle to form a cylinder (by joining a pair of parallel sides). Here's my first pass: Manipulate[ ParametricPlot3D[ t {Cos[theta], Sin[theta], rho} + (1 - t) {rho, -1, theta}, {theta, -Pi, Pi}, {rho, 0, 2}, PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}, {-1.5, 1.5}}, PerformanceGoal -> "Quality", ViewPoint -> {-2.3, 0.77, -2}, ViewVertical -> {-0.08, 1, -0.06}], {t, 0, 1}] I'd much prefer the simpler looking transformation (without the twists this animation shows) which we'd do by simply rotating the pair of parallel sides until they touch to form the cylinder. Answer Think of this as of a flexible strip of fixed length glued to the side of a cylinder with shrinking radius. If radius >> strip length, strip looks almost flat. Making radius smaller will curve the strip more and more until its ends meet. Manipulate[ ParametricPlot3D[{Sin[t]/a, Cos[t]/a, u}, {t, 0, a},

polynomials - Decomposition of a semialgebraic set into connected components

Is there any built-in function for doing decomposition of a semialgebraic set into connected components? The only way I now can think of is to use CylindricalAlgebraicDecomposition and to build connected componnets from its output: all terms connected with disjunction on first level are treated as vertexes of graph, two vartexes are connected if Length[FindInstance[v1 && v2, {vars}]] != 0 . On produced graph usual depth-first search based algorithm is used. But intuition says that such things are usually already implemented, hence the question. Answer EDIT : CylindricalDecomposition has been improved since I wrote this answer, probably in v11.2! Now it takes an optional topological operation argument. As a result, one can achieve the results described as connected below simply by adding such an argument to CylindricalDecomposition : decomp = List @@ BooleanMinimize@CylindricalDecomposition[eqns, {x, y}, "Com

front end - Create custom shortcut to change font color

Just wondering if I can create a custom shortcut key to change the font color of the notebook text. I've created a custom shortcut (in dkyeventtransactions.tr) to bring up the font color dialog, as so... Item[KeyEvent["q", Modifiers -> {Control}], FrontEndExecute[FrontEndToken["FontColorDialog"]]] but I'm hoping to create different shortcut keys to change the font directly to different colors, without using the font color selection dialog.

core language - Difficulty understanding difference between == and ===

After doing this: Clear[f, h] f[z_] = .66 I Cos[z]; h[c_] := {Re[c], Im[c], Nest[f, c, 200]}; complexpts = Flatten[Table[a + b I, {a, 0., 8, 8/249}, {b, -4., 4, 8/249}], 1]; t1 = Map[h, complexpts] // Chop This works: Select[t1, Not[#[[3]] === Indeterminate] &] But why doesn't this work: Select[t1, Not[#[[3]] == Indeterminate] &] And why doesn't this work: Select[t1, (#[[3]] != Indeterminate) &] Answer === ( SameQ ) is structural equality. a === b is True if a and b are exactly the same data structure (expressions), and False otherwise. For === it doesn't matter what a and b represent . Also, like nearly all Mathematica functions ending in Q , === always evaluates to either True or False (but nothing else). == is mathematical equality. a == b represents the equality of two mathematical expressions. It may or may not evaluate to True or False . Equations are represented in terms of == Indeterminate == someNumber never evaluates in Mathematica

functions - Defining Tags in Reap

I am trying to use Sow / Reap to replace Append in my code. The problem is that I need to define the tags within my code, but doing so doesn't reap the desired results. A simplified version of my code is Clear[tag]; Reap[tag = {a,b}; Sow[1, a];Sow[2,b];, tag] However, if I define my tag outside of Reap, then it works Clear[tag]; tag = {a,b}; Reap[Sow[1, a];Sow[2,b];, tag] Any ideas as to how I can define tags within my code? Answer Reap does not work that way: when you provide a list of tags for Reap only these tags are "watched for" and collected. This allows for much better memory management than collecting for all tags and discarding at the end. In essence it works something like this for declared tags 1 , 2 , 3 : {one, two, three} = {{},{},{}}; sow[x_, 1] := (one = {one, x}; x) sow[x_, 2] := (two = {two, x}; x) sow[x_, 3] := (three = {three, x}; x) sow[x_, _] := x SeedRandom[1] Do[sow[i, RandomInteger[10^6]], {i, 10^7}] Flatten /@ {one, two, three} MaxM

Nested list to graph

The following nested list can be regarded as a representation of a (tree) graph: li = {"fig", {"date", {"kumquat"}, {"papaya", {"peach"}, {"apple"}}}, {"mango", {"orange", {"pear"}, {"avocado"}}}, {"banana"}} In the above, a string is a node in the tree, and any lists that follow it are subtrees rooted at that node. What are some of the ways by which this can be converted into a graph (or more concretely, a list of DirectedEdge s)? I've come up with one way, listed below. But I wanted to learn about other interesting approaches - for instance, pattern replacements might be used? This is what I came up with: h[{str_String}] := Sequence[]; h[{str_String, ls__List}] := {DirectedEdge[str, #[[1]]], h@#} & /@ {ls}; edges = Flatten@h@li (* {"fig" \[DirectedEdge] "date", "date" \[DirectedEdge] "kumquat", "d

export - Exporting extremely large images; arrays generated via TensorProduct use 5 times as much RAM as expected?

I am generating plots of the roots of certain classes of polynomials, in the spirit of the multicolored visuals on the Wiki page on algebraic numbers . I've thus far been able to make some extremely spectacular plots, such as this 3600 x 3600 image of the roots of the monic quadratics and cubics (very low-res preview below) and this 4600 x 4600 image of the roots of the cubics with lead coefficient 5 (low-res preview below) and this 4600 x 4600 image of the roots of the cubics with lead coefficient 1 or 5 (low-res preview below). I have been running into a RAM usage bottleneck during the Export step as I try to make more detailed visuals. To make the images, I essentially execute Export["Imagename.PNG",Image[A]] where $A$ is roughly a $4600\times 4600\times 3$ rank-3 array specifying the RGB color channels. I was having issues with the MathKernel swallowing many gigabytes of RAM and initially thought it was from the Image Export step, but it turns out it's due to

history - Why did the Mathematica Language choose term rewriting instead of the Lambda Calculus as its basis?

Now we can see that Church was associated with the Simply Typed Lambda Calculus . Indeed, it seems he explained the Simply Typed Lambda Calculus in order to reduce misunderstanding about the Lambda Calculus. Now when John McCarthy created Lisp - he based it on the Lambda Calculus . This is by his own admission when he published "Recursive functions of symbolic expressions and their computation by machine, Part I" . You can read it here . Now we know that at the core of Mathematica is a Lisp-like system , but instead of being based purely on the Lambda Calculus, it is based on a term-rewriting system . Here the author states state: Mathematica is fundamentally a term rewriting system... a more general concept than the Lambda Calculus behind Lisp. My question is: Why did the Mathematica Language choose term rewriting instead of the Lambda Calculus as its basis? Answer The short answer is that the Mathematica Language did not choose anything. It was Stephen Wolfram back

plotting - Problem with Graphics`PolygonUtils`PolygonCombine

Writing: Normal@ParametricPlot[{x, x^2 t}, {x, 0, 2}, {t, 0, 1}] /. p : {__Polygon} :> Graphics`PolygonUtils`PolygonCombine[p] I get: but if I write: Normal@ParametricPlot[{x, x^2 t}, {x, 0, 2}, {t, 0, .1}] /. p : {__Polygon} :> Graphics`PolygonUtils`PolygonCombine[p] I get: How can I avoid this problem by having to use this function? Answer A small modification of the original code solves the problem: Normal@ParametricPlot[{x, x^2 t}, {x, 0, 2}, {t, 0, .1}] /. p : {{__Polygon} ..} :> Graphics`PolygonUtils`PolygonCombine[p] The new code also works for the initial problem .

list manipulation - Convolve two sets of (x,y) data sets

I have two sets of data in the form a={{.1,2},{.2,3},{.3,4},{.5,6}} b={{0,8},{.1,4},{.2,7},{.3,1},{.5,10},{.6,3}} Both data sets have even spacing, although the b dataset has significantly many more data points at higher and lower values of x . How do I convolve these data sets? Convolve[a,b] only works if I use just the y values of the datasets. Is there a way to convolve this data while still keeping these x values?

scoping - RecurrenceTable iteration variable not localized? Bug or user error?

I recently lost a lot of time on this and need to understand whether I have misunderstood MMA operations or there's a problem. I am using MMA 10.1 on Windows 7 64-bit. The essence of the issue is this: I believed that Table, RecurrenceTable etc, per the description of Table in the documentation, localise the iterating variable, and thus that using e.g. "i" in a RecurrenceTable and elsewhere in a notebook for some other purpose should not cause a conflict. ( Related question: ParametricPlot iterator not "block"-ed ) However as the three cases below show, unless the iterating variable is not reused or explicitly shielded by e.g. a Module in a definition incorporating a RecurrenceTable, I get the error that "1", "2", etc. cannot be used as a variable. Sample code follows (with forced clear for safety). The first two definitions of logisticMap cause no problems in subsequent use, but when the subsequent use reuses an unshielded iterating variable

Adding Trace produces error messages

This is very strange. As I was trying to debug this problem , I noticed when I add Trace then I get lots of internal errors generated. This also happens the first time after the kernel is started. So, with new fresh kernel, typing vars = {a, b, c, d}; x = Times @@ vars; $Assumptions = x > 0; Trace[Simplify[1 == Sqrt[x] Sqrt[1/x]], TraceInternal -> True] Gives But that is not all. Now with fresh kernel again, just adding one more variable to the list above, to make it 5 variables now, instead of 4, i.e. like this vars = {a, b, c, d, e}; x = Times @@ vars; $Assumptions = x > 0; Trace[Simplify[1 == Sqrt[x] Sqrt[1/x]], TraceInternal -> True] Now there is no error ! (make sure the kernel is fresh one before). So it only happens when there are 4 variables in the list. Not 3 and not 5 and not 6. Only 4 ! Why does it fail when there are only 4 variables in the list? What is so special about the number 4? Answer Short Version The ultimate cause of this problem is an evaluation le

Why does Mathematica fail to series expand this simple expression?

I wanted to expand the function $(x+2)^{x+2}$ around $x = -1$, that is, using Series[(x + 2)^(x + 2), {x, -1, 2}] and Mathematica returns the same expression. Why does this happen? The first term of a series expansion is simply $1^1 = 1$. However, I cannot even get this, from Series[(x + 2)^(x + 2), {x, -1, 0}]

notebooks - How to get complete Documentation Center graph of guide pages?

On the very last image below you can see a typical path of walking through Documentation Center guide pages. What is the best way to get the graph data and visualize the whole structure of these connections starting from the main table of contents page? An obvious thing to do is to look for example into directory: SetDirectory["C:\\Program Files\\Wolfram\\Research \\Mathematica\\8.0\\Documentation\\English\\System\\Guides"] FileNames[] // Column But I am not sure what is the next most efficient way to analyze the connections. A walk through guide pages ------------ UPDATE: new built-in WolframLanguageData ------------ I posted an answer in connection with newly released functionality - WL now contains data about itself . ------------ UPDATE: image from @Leoind data ------------ style = {VertexStyle -> White, VertexShapeFunction -> "Point", EdgeStyle -> Directive[Opacity[.3], Hue[.15, .5, .8]], Background -> Black, EdgeShapeFunction -&

front end - Poor anti-aliasing in Rotated text with ClearType on

There is a problem on my system that occurs when text is rotated 90 degrees as it is in frame labels. This only happens when ClearType is turned on, and only around 90 degrees of rotation. I am running Mathematica 7 on Windows 7. Input: Style["αβημπρτ", 20, FontFamily -> "Arial"] Rotate[%, # °] & /@ {90, 90.1, -90, 85, 95, 45, 0} Exhibit A: ClearType OFF Ehibit B: ClearType ON Notice the strongly inferior rendering of the text rotated 90° and 90.1°, but acceptable rendering of text at the other rotations including -90°. A close inspection of the images above will reveal that sub-pixel-rendering is disabled on rotated text except for the cases of 90°, 90.1°, and 0°. In the last case it works as as intended but it should apparently have been disabled (the default AA is used instead) for 90° and 90.1° as well. I do not want to turn off ClearType as it makes text more readable throughout my system except for this bug. I tried to be clever by nesting rotations b

numerics - Given a function $f(t,s)$, compute $max_{t_2in [0,1]}min_{t_1in [0,1]} |f(t_1,s_1)-f(t_2,s_2)|$

Given a continuous and bounded function $f(t,s)$ , $t,s\in[0,1]$ , I would like to compute $$\max_{t_2\in [0,1]}\min_{t_1\in [0,1]} |f(t_1,s_1)-f(t_2,s_2)|,$$ for each numeric values of $s_1$ and $s_2$ . I tried by combining NMaxValue and NMinValue but the time is prohibitively large. I read on the Internet that this distance is sometimes referred to as Fréchet or Hausdorff distance. Is there a built-in function in Mathematica that solves this max-min problem (something like NMaxMinValue)? Or which would be the correct algorithm to proceed with?

notebooks - All the group formatting available in Mathematica

I was wondering how many pre-defined group formatting style there is in Mathematica. From Format -> Style , one see that we can go from Title (for Alt+1) to Subsubsection (Alt+6). However, this does not seem to be exhaustive. This is because, if I press Tab on a line created from any of those formattings (from Alt+1 to Alt+6), then I can automatically "move down one level" each time. However, from Subsubsection , it seems that I can still go 2 more levels down, after which Tab does its "normal" job. Are these 2 additional formattings somewhere to be found in some documentation? Are they in any way "special" and can I assign keyboard shortcuts for them as for the other ones? Answer The option StyleKeyMapping controls "Tab" and "Backspace" does to the style (AFAIK, it is not documented). Row[Table[Most@NestWhileList["Tab" /. CurrentValue[{StyleDefinitions, #, StyleKeyMapping}]&, i, Not[StringMatchQ[#, "Ta

plotting - Fitting data without an equation

Let's say I have some data generated by anything. For practical sake, let's say I was able to generate a sequence of numbers through a recursion and I listed them out through a table of numbers. F[1] = 1; F[n_] := 3*F[n - 1] H = Table[F[n], {n, 1, 10}] Now I set the table of values to a variable 'w' ListPlot[H] Here I am plotting the data. What I want to do now is to "fit" a curve that connects all those points. I just want to see the fitted curve on the plot together the data points. I don't even need (or want to) see the equation that best fits the data. I tried using NonlinearModel and Fit, neither works well for me. The recursion is just an example. I could of course product new data from something else Answer If you just want to see the plot: ListPlot[H, Mesh -> Full, Joined -> True, PlotRange -> All, InterpolationOrder -> 2]

graphics - Adding Math to Plots

I have several formulas I would like to place at specific coordinates in a Graphics object I have already created. I need to be able to choose bold or not as well as how large to make it. I am unsure how to control the size of the text as well as why Mathematica will not place it. Specifically, it continues to try to evaluate my text. One of the objects I wish to place on the plot is (since it won't let me post a picture) $$M^\mu = \oplus_{\lambda \ge \mu} \,m \, \lambda_\mu \, S^\mu$$ However, Mathematica continues to try to evaluate the direct sum rather than just place it at say the point (0,0). Here is the code I am trying at the moment: Graphics[{Style[HoldForm[M^μ == \!\(*UnderscriptBox[(StandardForm[⊕]), (λ ≥ μ)]\) m Subscript[λ, μ] S^μ], Medium], FormatType -> StandardForm}] Any ideas?

factorization - Find the a factor of an integer which is nearest to another integer

If I know two integers $n$ and $m$ and $m < n$, how can I find two different integers $x$ and $y$ that are nearest to $m$, and satisfy Mod[n,x]==Mod[n,y]==0 ? For example, f[720,8] ==> {8,9} f[720,20] ==> {18,20} If $n$ is small, we can brute force to test whether an integer is a factor of $n$, and find the nearest two of the factors: twoNear[n_Integer, m_Integer] := Module[{ls, sortls}, ls = Select[Range[1, n], Mod[n, #] == 0 &]; sortls = Sort[Transpose[{ls - m, ls}], Abs[#1[[1]]] < Abs[#2[[1]]] &]; Sort@sortls[[1 ;; 2, 2]] ] twoNear[720,8] twoNear[720,20] (*{8, 9}*) (*{18, 20}*) but how to deal with problems such as n=20!, m=1*^9 , n=40!,m=1*^20 ? Answer My lucky day (night). I get to take my own answer which was of dubious value here and basically repurpose it to give a good response to this question. We set this up as a mixed linear program by trying to get sums of logs of factors as close to m as possible, subject to coefficients being nonnegative

difference equations - RecurrenceTable doesn't evaluate with constant right-hand side

One of my functions automatically generates systems for RecurrenceTable . Usually works fine, but today I encountered a problem. If the right-hand side is a constant, it doesn't evaluate: RecurrenceTable[{n[t + 1] == 2, n[0] == 1}, n, {t, 0, 10}] (* RecurrenceTable[{n[t + 1] == 2, n[0] == 1}, n, {t, 0, 10}] *) One workaround I discovered: RecurrenceTable[{n[t + 1] == 2 + Unevaluated[0 n[t]], n[0] == 1}, n, {t, 0, 10}] (* {1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2} *) Are there others? Should this be considered a bug?

graphics3d - Extract current viewing parameters from a 3D view?

Is there a way to find out the current viewing parameters of a 3D view? What often happens is that I create a view, for example: Graphics3D[{Blue, Cuboid[], Yellow, Sphere[]}, Boxed -> False] and then spend some time adjusting it using the mouse to pan, zoom, and rotate it: Now I'd like to know what those settings (view point, etc.) are, so that they can be integrated as defaults into the next edit. It looks like an easy problem but I can't find out how to do it. At the moment there's a lot of trial and error involved. Answer You can dynamically extract ViewPoint and others like this (also useful for synchronization of different plots etc.): vp = Options[Graphics3D, ViewPoint][[1, 2]]; Graphics3D[Cuboid[], ViewPoint -> Dynamic[vp]] This value is now constantly updated: Dynamic[vp] {1.3, -2.4, 2.} This seem also to work fine with other functions that use the ViewPoint option. Below, ViewPoint and ViewVertical are in sync for both objects: {vp, vv} = Options[Graph