Tag Info

Hot answers tagged

25

The power of Mathematica's syntax allows us to create a dice in several different ways. Here's one way that I like: dice[n_Integer] := dice[n, Black] Format[dice[n_Integer, c_]] := With[{ dots = {1 -> {5}, 2 -> {3, 7}, 3 -> {3, 5, 7}, 4 -> {1, 3, 7, 9}, 5 -> {1, 3, 5, 7, 9}, 6 -> {1, 2, 3, 7, 8, 9}} /. l : ...


20

We have unicode support so we can use the following strings: {"⚀", "⚁", "⚂", "⚃", "⚄", "⚅"}: dice = FromCharacterCode /@ Range[9856, 9856 + 5]; Grid[Partition[RandomInteger[{1, 6}, {50, 2}], 5] /. { i : {__Integer} :> Style[ Row[dice[[i]], Spacer[1]], {Large, Total[i] /. {7 -> Red, _ -> Black}}]} , Frame -> All]


16

After importing a free dice 3D model {pd, vd} = Import["c:\\dice.stl", #] & /@ {"PolygonData", "VertexData"}; g2 = Translate[GraphicsComplex[vd, Polygon /@ pd], {-10, -37.5, -10}]; rv = {{0, 0, -1}, {0, -1, 0}, {0, 0, 1}, {0, 1, 0}, {-1, 0, 0}, {1, 0, 0}}; dice[x_List, n_Integer] := Rasterize@(Graphics3D[{EdgeForm[None], Blue, Rotate[g2,{{0, 0, ...


15

nb2 = NotebookOpen[$InstallationDirectory <> $PathnameSeparator <> "SystemFiles" <> $PathnameSeparator <> "FrontEnd" <> $PathnameSeparator <> "StyleSheets" <> $PathnameSeparator <> "Core.nb"]; Note that some of the named styles in the core stylesheet styles are empty, i.e. the style name is ...


15

Declaration: This method for Windows is based on the .NET code from Todd Gayley's this wonderful answer. My .NET knowledge is absolutely ZERO, all credit goes to Todd. Code: The main idea is to extract the "Input"-style code string, convert it to the UTF-16 little endian form, which is the standard byte order in Windows, feed the bytes to system clipboard ...


12

Typesetting in Text cells Cell[TextData[Cell[BoxData[ FormBox[ RowBox[{ FractionBox["1", "N"], RowBox[{ UnderoverscriptBox["\[Sum]", RowBox[{"i", "=", "1"}], "N"], FractionBox[ RowBox[{ SubsuperscriptBox[ OverscriptBox["x","~"], "j", "i"], "(", RowBox[{"k", "|", "k"}], ")"}], SqrtBox[ ...


12

You can always write your own version of PeriodicForm: ClearAll@PeriodicForm PeriodicForm[n_] := RealDigits[n] /. {{d___Integer, {i__Integer} ...}, l_Integer} :> PeriodicForm[n, l, {d}, {i}] Format[PeriodicForm[n_, l_, d_, i_]] ^:= Interpretation[Row[{ FromDigits[d ~Take~ l] /. {} -> 0, ".", Sequence @@ d ~Drop~ l, ...


10

Using the same (well slightly modified) Wolfram demonstrations code as bill s dicelist = {{Disk[{0, 0}, 0.2]}, {Disk[{0.6, 0.6}, 0.2], Disk[{-0.6, -0.6}, 0.2]}, {Disk[{0, 0}, 0.2], Disk[{0.6, 0.6}, 0.2], Disk[{-0.6, -0.6}, 0.2]}, {Disk[{0.6, 0.6}, 0.2], Disk[{-0.6, -0.6}, 0.2], Disk[{0.6, -0.6}, 0.2], Disk[{-0.6, 0.6}, 0.2]}, ...


10

Mathematica's abbreviated PostScript What you see after pressing Ctrl + Shift + E in this case is Mathematica's abbreviated PostScript code. You can find some information about it in MathGroups archives: Mathematica abbreviated PostScript This is the PostScript that is understood by the notebook front end and is generated by the Mathematica ...


10

You can often get tolerable results from the likes of GraphicsColumn by specifying explicit values for ImagePadding, making sure you allow enough padding for frame or axis labels. Here's a stacked plot using GraphicsColumn: commonopts = {Mesh -> None, InterpolationOrder -> 0, PlotRange -> All, PlotStyle -> Thick, Frame -> True, Axes ...


10

ToCCodeString has the "Indent" option, which defaults to None. Set it to the number of tabs you want for an indentation, and you should be fine.


10

Caveat: Since this uses hidden, undocumented functions, it will probably break at some point in the future. Also, I do not have any knowledge of how these functions work, except guesses from observed behavior. Some information is available via Information. Under the hood of TexForm is Convert`TeX`ExpressionToTeX, which in turn calls Convert`TeX`BoxesToTeX ...


9

Here's one way, borrowing heavily from one of the Wolfram demonstrations. dicelist[rb_] := {{rb, Disk[{0, 0}, 0.2]}, {rb, Disk[{0.6, 0.6}, 0.2], Disk[{-0.6, -0.6}, 0.2]}, {rb, Disk[{0, 0}, 0.2], Disk[{0.6, 0.6}, 0.2], Disk[{-0.6, -0.6}, 0.2]}, {rb, Disk[{0.6, 0.6}, 0.2], Disk[{-0.6, -0.6}, 0.2], Disk[{0.6, -0.6}, 0.2], Disk[{-0.6, 0.6}, 0.2]}, {rb, Disk[{0, ...


9

Another dice: dots = {{{2, 2}}, {{0.85`, 0.85`}, {3.15`, 3.15`}}, {{0.85`, 0.85`}, {2, 2}, {3.15`, 3.15`}}, {{0.85`, 3.15`}, {0.85`, 0.85`}, {3.15`, 3.15`}, {3.15`, 0.85`}}, {{0.85`, 3.15`}, {0.85`, 0.85`}, {2, 2}, {3.15`, 3.15`}, {3.15`, 0.85`}}, {{0.85`, 3.15`}, {0.85`, 0.85`}, {3.15`, 3.15`}, {3.15`, 0.85`}, {0.85`, 2}, {3.15`, 2}}}; ...


9

Update It's probably easier to use Edit -> Copy As -> Bitmap from the menubar. Changing the magnification of the notebook will change the size of the image that gets sent to the clipboard Previous answer There's likely a better answer out there, but I use a hack of the SEUploader to do this. toclipboard2[] := If[ MemberQ[Hold[{}, $Failed, ...


9

Another approach: mark[s_, where_] := With[{n = ToString@s}, Row@{StringDrop[n, -where], Style[StringTake[n, -where], Red]}] Let's say you want to mark last 3 digits: mark[N[Pi, 45], 3] And a little bit more general approach: mark[s_, w_] := With[{n = ToString@s}, Row@MapAt[Style[#, Bold, Red] &, ...


8

As Mr.Wizard showed me here. Run the following with " " replaced with the pasted data. For example: CellPrint@Cell[ First@FrontEndExecute@UndocumentedTestFEParserPacket["Print[ \"test\" ]", False], "Input"] And here is a Palette with a Button that automates the process. CreatePalette@Button["Paste", NotebookWrite[InputNotebook[], ...


8

As Yves already mentioned, you can easily create and edit notebooks through Mathematica commands. A start would be this tutorial, which you can find in the Documentation Center under tutorial/ManipulatingNotebooksFromTheKernel Here is a short example printing the i values into a new notebook: nb = CreateDocument[]; For[i = 1, i <= 10, i++, ...


8

In my opinion, GraphicsRow is no good. Neither is GraphicsGrid or GraphicsColumn. I can't remember all the reasons right now, but I stopped using them a couple years ago and now exclusively use Grid. When I do Grid[{{plot1, plot2}}] I get which I think is what you want.


8

The answer You create metafiles every time when you copy graphics from Mathematica FrontEnd and paste it in MS Word because it is native format for exchanging vector graphics under Windows. So your question is actually about corrupted metafiles in MS Word document opened on a machine without Mathematica fonts installed. This behavior is expected because ...


8

Here is a very robust (!!) method expr = (z14 z43 (z01 + z03 + z12 + z32) + z01 z12 z43 + z03 z14 z32); StringReplace[ToString[expr, TeXForm], " " :> "\\times"] Using Ctrl+Shift+C to copy as plain text results in ...


8

A reliable approach would use the third argument of Reduce as variables to eliminate (see Behavior of Reduce with variables as domain) Reduce[{p == a b x + b^2 y + a c z, a b == 1, b^2 == 2, a c == 4}, {p}, {a, b, c}] p == x + 2 y + 4 z In the former editions of Mathematica (ver <= 4) Reduce used the third argument for eliminating another ...


7

I assume you know (1,2) will result in an error while interpreting by FE and that form you need is for output/presentation purposes: StringForm["(``,``)", ##] & @@@ {{-3, 0}, {0, -1}, {1, -2}, {2, -5}, {4, 7}, {5, 4}, {6, 3}, {9, 2}} {(-3,0),(0,-1),(1,-2),(2,-5),(4,7),(5,4),(6,3),(9,2)}


7

To get PeriodicForm working in Mathematica 9 (and probably other versions after 6) you need to first download the obsolete package from the Wolfram Library Archive. Run the package, ignore the errors and have fun: Get["http://library.wolfram.com/infocenter/MathSource/6773/\ ContinuedFractions.m?file_id=6182"] PeriodicForm[RealDigits[19/7]]


6

I think your approach is fine; in fact I just recommended something similar in another answer. However, for the best handing of using your formatted output as input may want to use MakeBoxes for the reason described by Michael Pilat. You also might consider putting a list your subscripted symbols in a global variable for easy changes, or Blocking. ...


6

Taking the question as "how to replace the first argument in $g(a,b)$ as well as all of its derivatives", you can do this: Check the InputForm of the derivative: D[g[1, y], {y, 2}] // InputForm (* ==> Derivative[0, 2][g][1, y] *) Add a corresponding pattern to the replacement rules: f[1, y] D[g[1, y], {y, 2}] /. {g[1, y] -> g[x, y], ...


6

Warning: The conversion below can lead to wrong results in the C-code. Be aware of that. Since you complain anyway about "Sqrt" and "Pow" have you considered writing your own cform? The real CForm seems a bit stubborn about the numerical evaluation of rational expressions and with your own version you can cure this too. A very basic hack could look like ...


6

When I posted this question, I said I wouldn't post my answer if someone else posted an equivalent one, but here I am doing it. Am I going back on my word?. The answer given by ssch is close enough to mine to qualify as equivalent for all practical purposes. However, although both our answers are based on the same insight: that no graphics are needed because ...


6

I am rather aghast at how poor those solutions are! Are the two sets of data suppose to be related? They have the same horizontal range so why not put them on top of each other and have only one x axis? Then it is really poor technique to use an Axis plot when the data is crossing the axis. The ticks and labels clobber the data! Look in a journal such as ...


6

See last paragraph in Scope:- http://reference.wolfram.com/mathematica/ref/ExponentFunction.html nFormat = NumberForm[#, {\[Infinity], 2}, NumberPoint -> ",", NumberSeparator -> ".", DigitBlock -> 3, ExponentFunction -> (Null &)] &;



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