29

You can use ToExpression. Paste your content inside quotes and select "yes", in order to escape backslashes and use them verbatim: ToExpression["string", TeXForm, HoldForm]


25

Here is my attempt to figure out how the correct colorspace linearization should be made. I used specially designed test images by Eric Brasseur for comparison of two colorspace linearization algorithms. The first algorithm is just an implementation of the corresponding formulae from the Specification of sRGB made by Jari Paljakka who started the discussion ...


22

TeXForm is indeed your friend. It even gives you nicely formatted code: Table[RandomInteger[10], {3}, {4}] // TeXForm gives (* \left( \begin{array}{cccc} 9 & 5 & 10 & 9 \\ 6 & 10 & 3 & 9 \\ 9 & 5 & 9 & 7 \\ \end{array} \right) *)


22

str = {"1,2,3,5,10,12,13,17,26,30,32,41,42,43,113,115,121,125"} Flatten@ToExpression@StringSplit[str, ","] Short explanation: After executing StringSplit you get a list of separated "StringNumbers" like {{"1", "2", ... "125"}} ToExpression converts these "StringNumbers" to Integers. Flatten removes the outermost brackets. You can even omit Flatten by ...


22

SetPrecision[] does this: SetPrecision[0.1, ∞] 3602879701896397/36028797018963968


20

I'm going to take this as a general question, referring to all atomic objects, not just DelaunayMesh. By design, atomic objects like DelaunayMesh, SparseArray, Graph, etc. or even Association and Rational are not meant to be accessed directly as a Mathematica expression. There are various reasons why an object was made atomic, typically related to ...


18

A year late, but here are my thoughts: As Szabolcs showed, extracting the Line primitives from a RegionPlot provides a convenient way to produce a polygon from an image. The function imgToPolys below does just that - it's essentially the same as Szabolcs' code but I use ImageValue instead of creating an interpolating function from the image data. Of course,...


18

pic = Import @ "http://i.stack.imgur.com/RJs60.png" ListPlot3D can work with an array of values too. The problem is that you have quadruplets there, RGB and alpha channel. Convert it: ListPlot3D[ Reverse @ ImageData @ RemoveAlphaChannel @ ColorConvert[pic, "Grayscale"], AxesLabel -> {"x", "y", "z"} ]


17

If you already have a Graphics3D object, then you can recreate an Image3D object by stacking slices of your graphics along an axis. Here's an example. We start with your object: obj = Plot3D[x^2 - y^2, {x, -1, 1}, {y, -1, 1}] Using the following rudimentary "slice" function, we can generate slices of the function at a given value of $x$: slice[obj_, x_, ...


16

Mathematica 10 introduces IntegerName: IntegerName[n] gives a string containing the full English name of the integer n. IntegerName[n,"type"] gives a string of the specified type. Possible types include: "DigitsWords" a combination of three-digit numbers and words "Words" using only words "Approximate" the first few digits ...


16

The coolest way is to check the answer to this question by David Carraher. I am shamelessly stealing his code here to write a function that gives you rules for up to maxNumber: ordinalRule[maxNumber_Integer] /; maxNumber > 0 := Block[{p}, Thread[ Function[{x}, x -> StringSplit[SpokenString[p[[#]]]][[2]] &[x] // Quiet] /@ ...


16

I think this is the simplest fast way to convert an atomic expression to an equivalent compound form, to be able to inspect and manipulate its "apparent" full form: g = RandomGraph[{5,8}]; (* this is our atomic expression *) ml = LinkCreate[LinkMode -> Loopback]; LinkWrite[ml, With[{e = g}, Hold[e]]] LinkRead[ml] LinkClose[ml] (* Hold[Graph[{1, 2, 3, 4,...


15

To minimize confusion I've reduced the code to one approach. ClearAll[Ten, Ace]; getImage = WolframAlpha[ #, {{"Image", 1}, "Content"}, InputAssumptions -> {"*MC.%7E-_*CardRank-"} ] &; With[{ pic = ToBoxes@getImage[#] }, #2 /: MakeBoxes[#2, fmt_] := InterpretationBox[pic, #3] ] & @@@ { {"10 of spades", Ten, 10}, {"Ace of hearts",...


14

It is well-documented! According to the Documentation page for StandardForm, StandardForm generates output that gives a unique and unambiguous representation of Wolfram Language expressions, suitable for use as input. » StandardForm is the standard format type used for both input and output of Wolfram Language expressions in notebooks. ...


13

A bug report has been generated on this issue, but I don't believe any resources are being expended on it at the present time (note that the more user reports are received on an issue, the more likely it is that the issue will get resources). As a workaround, it is possible to hook into the internal code that is used for Graphics3D primitives. The key idea ...


13

N A one-character answer is disallowed by SE, so I will expand. N is mostly what I use. If I have an expression like $2 x + 3$, I sometimes write it 2. x + 3. in Mathematica; then if x is numeric, whether it happens to be an Integer or not, the expression will always be Real or Complex.


13

spec = {{{0, 0}, a}, {{0, 1}, b}, {{1, 0}, c}, {{1, 1}, d}}; Normal @ SparseArray[# + 1 -> #2 & @@@ spec] {{a, b}, {c, d}}


12

data = FinancialData["SPY", "Jan. 1, 2011"] /. {d_List, v_} :> {AbsoluteTime@d, v}; model = a x^4 + b x^3 + c x^2 + d x + e; fit = FindFit[data, model, {a, b, c, d, e}, x] modelf = Function[{x}, Evaluate[model /. fit]] Plot[modelf[x], {x, Min@data[[All, 1]], Max@data[[All, 1]]}, Epilog -> Map[Point, data]] Edit Better (tick labels showing dates) ...


12

I'd do the minimum necessary to make a legitimate, unambiguous Mathematica expression, and then let Mathematica rewrite it. stepexpr[s_] := ToExpression[StringReplace[s, {"(" -> " dummy[", ")" -> "]"}]] /. op_Symbol dummy[args__] -> op[args] /. dummy -> List This replaces () expressions with a dummy[] function in the string, making a legal ...


12

The most efficient way is not to use DayName but this: DateValue[{2012, 12, 24}, "ISOWeekDay"] Regarding Robert's comment Well, that was a correct answer but not on the exact question. What if I don't have a date but just a weekday as e.g. Monday how do I now get the ISOWeekDay number. Without explicitly coding. Is there a a ready to use MMA function f ...


12

For your first question, if we gather the factors into a single variable z, there's a simple hypergeometric function: f[z_] = (-1)^(1/4) EllipticF[I ArcSinh[(-1)^(1/4) z], -1]; g[z_] = -z Hypergeometric2F1[1/4, 1/2, 5/4, -z^4]; These two functions are the same, even though FullSimplify cannot prove it: Series[f[z] - g[z], {z, 0, 100}] (* O[z]^101 *) Plot[...


11

I added timings - 3rd from the bottom is fastest. I am sure there are faster versions. If speed is important you can parallelize or come up with a Compile-ed solution. In[1]:= list = RandomInteger[{3, 12}, {10^7, 2}]; In[2]:= list // Developer`PackedArrayQ Out[2]= True In[3]:= Table[#1, {#2}] & @@@ list // Flatten; // AbsoluteTiming Out[3]= {22....


11

While this is overkill, I'm just trying everything I can do with these new (in V10) and exciting Mesh and Region functions. So here we go: f[x_, y_] := -E^(-(1 + x)^2 - y^2)/3 + 3*E^(-x^2 - (1 + y)^2)*(1 - x)^2 - 10*E^(-x^2 - y^2)*(x/5 - x^3 - y^5); gr = Plot3D[f[x, y], {x, -3, 3}, {y, -3, 3}, PlotRange -> All, PlotPoints -> 100]; We ...


11

Not as clean as J.M.'s method but this seems to give the same result: 0.1 ~RealDigits~ 2 ~FromDigits~ 2 3602879701896397/36028797018963968 Follow with Numerator and Denominator if needed.


11

Motivation Recently, I wanted to extract parts of an atomic expression, and my first thought was to use a ToExpression/ToString roundtrip where I inactivate the atomic head. I then decided that it would be worthwhile to have a function to convert an atomic object into an inactive version where the head is wrapped in Inactive. Then, I thought such a function ...


11

Try StringRiffle[{0, 0, 1, 2, 3, 4}, ""] "001234" Introduced in version 10.1 or in postfix as follows: {0, 0, 1, 2, 3, 4} // StringRiffle[#, ""] &


11

DateObject itself can be used for this: date1 // FullForm DateObject[List[2019,9,14,0,0,0],"Instant","Gregorian",-7.`] DateObject[date1, "Day"] // FullForm DateObject[List[2019,9,14],"Day","Gregorian",-7.`]


10

I've got my own package that I've used for a few years to generate LaTeX from Mathematica. All the labs on my Mathematica course page were produced with this package. Here's a handout on probability theory for Calc II students that was produced by the package. Unfortunately, it's not at all polished and really not usable by anyone but me. I can present ...


10

There are two parts to accessing the contents of a Java Map object. The first is to traverse the iterator interface to extract the map elements. The second is to use accessor methods on those elements to extract their properties. For the purpose of discussion, let's create a map from strings to Java date objects: Needs["JLink`"] InstallJava[]; $map = ...


10

The reason your original code fails is that the TreeFrom object is only formatted as Graphics object, meaning that it converted for display rather that as part of the normal evaluation sequence. You can convert to and from box form to recover your Graphics object: tf = TreeForm[a + b^2 + c^3 + d]; gr = tf // ToBoxes // ToExpression gr /. (x_Framed :>...


Only top voted, non community-wiki answers of a minimum length are eligible