# Tag Info

37

I think there is a neat solution. We have curios function ListCurvePathPlot: pic = Thinning@Binarize[GradientFilter[Rasterize[Style["\[Euro]", FontFamily -> "Times"], ImageSize -> 200] // Image, 1]]; pdata = Position[ImageData[pic], 1]; lcp = ListCurvePathPlot[pdata] Now this is of course Graphics containing Line with set of points lcp[[1, 1, 3, ...

36

Assuming nb is your notebook object, then this will do what you want without touching the clipboard: First[FrontEndExecute[ FrontEndExportPacket[NotebookSelection[nb], "InputText"]]] Some notes about this solution: It preserves evaluation semantics precisely, regardless of typesetting. It does not dirty the clipboard If you prefer to get the appearance ...

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 ...

25

Using StringPatternPatternConvert we can find the regexp into which Mathematica converts the original string expression: StringPatternPatternConvert[Except["b"] .. ~~ "b"][] "(?ms)(?:[^b])+b" The only difference as compared to the direct semantic translation is that the negated character class [^b] is enclosed by redundant non-capturing group (?: … )....

24

Possible answer using ClusteringComponents: image=Rasterize[ Style["Sjoerd!",Italic,FontSize->24,FontFamily->"Times"], "Image",ImageSize->200] cluster=ClusteringComponents[ImageReflect[image,Left->Right]]; ListPlot3D[cluster,Mesh->False,BoxRatios->{3,1,1},Boxed->False, Axes->False,Lighting->"Neutral", ViewPoint->{-0....

23

You can recast this to a problem of finding a Hamiltonian cycle in a graph constructed in a certain way from your points (distance graph). First, compute mutual distances: distances = With[{tr = Transpose[N@pdata]}, Function[point, Sqrt[Total[(point - tr)^2]]] /@ N[pdata]]; Now, construct an adjacency matrix by stating that two vertices (points) are ...

22

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

21

I tried FindCurvePath and FindShortestTour, but didn't succeed. The latter is too slow to finish on my machine, except when using the "Greedy" method, which does not give a perfect solution. Here's something different: matrix = Rasterize[ Style["\[Euro]", FontFamily -> "Times", Antialiasing -> False], "Data", ImageSize -> 200][[All, All, ...

21

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 ...

20

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

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 ...

19

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]

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

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,...

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[[#]]]][] &[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

From the sublime to the ridiculous. By way of contrast, here's another approach to 3D text rendering: sjoerd = Image[ Rasterize[" sjoerd ", RasterSize -> 900, ImageSize -> 900]]; Manipulate[ ImagePerspectiveTransformation[sjoerd, ScalingMatrix[s, {v1, v2, v3}], Padding -> "Periodic", Resampling -> "Bicubic"], {{s, .2}, 0....

15

Nested WolframAlpha approach, showing the intermediate steps: numberString[a_, k_: 10] := FixedPointList[ StringReplace[#, b : (DigitCharacter ..) :> WolframAlpha["spell " <> b, {{"Result", 1}, "Plaintext"}]] &, a, k] numberString["123456"] (* ==> {"123456", "123 thousand and 456", "one hundred twenty-three \ thousand and ...

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",...

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

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. ...

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

Posting as an answer per request. See http://forums.wolfram.com/mathgroup/archive/2011/Mar/msg00529.html Caveat: It's been almost a year since I've toyed with that code. Strange things can happen to code left on the dusty shelves of Usenet. The basic idea was similar to Leonid's: use some proximity measure to find neighbor pairs. And be prepared for some ...

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:= list = RandomInteger[{3, 12}, {10^7, 2}]; In:= list // DeveloperPackedArrayQ Out= True In:= Table[#1, {#2}] & @@@ list // Flatten; // AbsoluteTiming Out= {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 ...

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