Tag Info

Hot answers tagged

37

You can use custom transformation rules, for example: -11 - 2 x + x^2 - 4 y + y^2 - 6 z + z^2 //. (a : _ : 1)*s_Symbol^2 + (b : _ : 1)*s_ + rest__ :> a (s + b/(2 a))^2 - b^2/(4 a) + rest returns (* -25 + (-1 + x)^2 + (-2 + y)^2 + (-3 + z)^2 *) The above rule does not account for cases where b is zero, but those are easy to add too, if ...


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


22

Since a native method is not forthcoming, I shall post my file based circumvention, for Windows. You will need to have this utility in the command path (it apparently is stock with Windows 7). copyUnicode[expr_] := Run["clip <", Export["$Clipboard.temp", ToString[expr, InputForm], "Text", CharacterEncoding -> "Unicode"] ]; Usage: expr ...


21

If this is something you want in general, try: SetOptions[$FrontEnd, PrintPrecision-> 10] and if you just want it for a specific notebook, then do: SetOptions[InputNotebook[], PrintPrecision-> 10]


21

I always use IntegerString for this (I also number my files in a similar way): In[1]:= IntegerString[#, 10, 2] & /@ Range[87] Out[1]= {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", \ "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", \ "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", \ "33", "34", "35", ...


21

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]


20

You can use TrigExpand to expand all trigonometric functions to fundamental forms and then Eliminate solves the rest eq1 = Sin[x]^8 + 2 Cos[x]^8 - 1/2 Cos[2 x]^2 + 4 Sin[x]^2 == 0; eq2 = t == Cos[2 x] Eliminate[TrigExpand[{eq1, eq2}], x]


19

Edit: Quoting from Heike´s comment: "The font families used for Greek, script, gothic, and double struck symbols are respectively "Mathematica1", "Mathematica5", "Mathematica6", and "Mathematica7" " With this knowledge, just use Styletogether with the FontFamily option: Style["Doth this help?", FontFamily -> "Mathematica6", FontSize -> 100] ...


17

I've had a need for such a function several times, and I found this implementation of C-style *printf functions, by Vlad Seghete. To use it, all you need to do is extract the files to $UserBaseDirectory/MathPrintF/ and you're all set. Here's an example once you've installed it: <<MathPrintF` sprintf["%d %s %d %s, %s %s %s %s", Sequence @@ ...


17

PrintPrecision You can control the number of digits displayed using the PrintPrecision option. You have a number of options for its use. You can set it Globally or for the specific Notebook using the Options Inspector. You can also use it directly with Style: Style[123.189094, PrintPrecision -> 10] 123.189094 You can set it temporarily for one ...


16

Another option is to set FormatType -> OutputForm on the $Output stream: SetOptions[ $Output, FormatType -> OutputForm ]; Print["Hello"]; Or call OutputForm on the string itself: Print[ OutputForm["Hello"] ];


16

Not as such. The closest equivalent is StringForm, but it doesn't provide the formatting options that the printf family does. StringForm gets a lot of use in the creation of messages. Example: StringForm["The value of Pi is ``", NumberForm[N[Pi], 3]] (* ==> "The value of Pi is 3.14" *) Note that StringForm does not create a string, it merely ...


16

Mathematica's Graph related functionality is pretty great. You can easily style vertexes, edges and their labels, apply interesting functions. For small increase in code sophistication you gain quite a bit of advantage. Your data: poli = {{1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {5, 2}, {4, 2}, {3, 2}, {2, 2}, {1, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, ...


16

An even simpler way that does not require you to figure out the tick positions, is to set the tick font opacity to 0 and the tick font size to 0 to avoid the excess margin where the ticks would have been. Here's an example: RegionPlot[Sin[x y] > 0, {x, -1, 1}, {y, -1, 1}, FrameTicksStyle -> Directive[FontOpacity -> 0, FontSize -> 0]] ...


16

Recall that the rendering of Graphics has nothing to do with evaluation. It is done entirely in typesetting. And therefore, a robust solution will treat this as a problem of typesetting, and not as a problem of evaluation. Once you frame the problem properly, the solution is fairly straightforward. What you want to do is to change the typesetting of Hold ...


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


16

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


15

This answer is just a quick hack. I think that to make true extensible character might not be something that an end-user can do... Anyway, redefine the formatting for OverHat using OverHat /: MakeBoxes[OverHat[a_], form_] := With[{s = First[Rasterize[a, "RasterSize"]], ab = MakeBoxes[a]}, With[{sl = N[2 Log[2 s]]}, ...


15

Just ask for it in InputForm: In[1]:= ToString[12345.^6, InputForm] Out[1]= 3.539537889086625*^24


15

Here is a definition for mixedForm that works for all cases, i.e. proper and improper fractions and integers. Clear[mixedForm] mixedForm[Rational[x_, y_]] := If[Abs@x > y, HoldForm[#1 + #2/y], x/y] & @@ (Sign@x QuotientRemainder[Abs@x, y]) mixedForm[x_Integer] := x Some examples: mixedForm /@ {2, 4/5, 10/3, -3/4, -5/2} Out[1]= {2, 4/5, 3 + ...


15

Start by making some similarity measure of sentences, here I use one that takes number of words in common divided by number of words in longest sentence. The measure is then used to connect sentences that are similar enough in a graph and extracts the connected components: strs = {"Barack Obama", "Barack H. Obama", "Barack Hussein Obama", "Obama ...


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


14

There is already a built in function to handle this — it's called ScientificForm. You can get the output you desire as: ScientificForm[12345.^6, NumberFormat -> (#1 <> "E" <> #3 &)] // ToString Out[1]= 3.53954E24 StringForm only affects the display, so to export it correctly as a string to a log file, you'll have to wrap it in ToString ...


14

Maybe this : NumberForm[#, 10] &@ {123.189094`, 123.189263`} {123.189094, 123.189263 } ? Edit Consider also this utility of NumberForm[ x, {m, k}] giving m real digits of x with k digits to the right of the decimal point, e.g. NumberForm[#, {10, 7}] &@ { 197.9898987322333, 201.73205080756887 } { 197.9898987, 201.7320508 }


14

If you want the minor ticks too, you can use the following function: SetAttributes[dtZahl, Listable] dtZahl[x_] := Block[{n}, If[IntegerQ[n = Rationalize[x]], n, x]] exponentForm[x_?NumberQ] := Module[{me = MantissaExponent[x], num, exp}, If[MemberQ[{0, 0., 1, 1., -1, -1.}, x], Return[IntegerPart[x]]]; exp = Superscript["\[CenterDot]10", me[[2]] ...


14

The answer to your first question is that PlotMarkers doesn't really use a graphics primitive, but uses font based markers as a proxy for it. This can lead to errors in positioning on some OSes. I'm guessing that PlotStyle has something of the form ToString@HoldForm[...] when the input is a list, which is why None and False or anything else get converted to ...


14

If you want to order your terms this way but not perform the other formatting that TraditionalForm does, you might like to try the (undocumented) PolynomialForm[expr, TraditionalOrder -> True]. That will change output like this: Expand[(x+y-1)^3] (* -> -1+3 x-3 x^2+x^3+3 y-6 x y+3 x^2 y-3 y^2+3 x y^2+y^3 *) into this: ...


14

You can use PolynomialForm : Collect[(1 + x + Cos[s] x^2)^3, x] // PolynomialForm[#, TraditionalOrder -> True] & Cos[s]^3 x^6 + 3 Cos[s]^2 x^5 + (3 Cos[s]^2 + 3 Cos[s]) x^4 + (6 Cos[s] + 1) x^3 + (3 Cos[s] + 3) x^2 + 3 x + 1


13

You were definitely on the right track with MonomialList. Here is a solution. Others will probably find nicer ways. Using the trick found here, we first define a Format that looks like "Plus" but doesn't rearrange things: Format[myPlus[expr__]] := Row[Riffle[{expr}, "+"]] With this format in hand, we can wrap your original function in the following: ...


13

This is similar to my Log question and similar methods can be used. $PrePrint = # /. { Csc[z_] :> 1 / Defer@Sin[z], Sec[z_] :> 1 / Defer@Cos[z] } &; Example: (x + y) Csc[x] Sec[y] (x + y)/(Cos[y] Sin[x])



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