Tag Info

Hot answers tagged

31

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


18

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


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

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


14

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


14

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


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


13

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


13

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


12

Make a graphics where you put at each position {i,j} the entries of your matrix. The only thing left to do is to transform your path positions from the form {p1,p2,...} into {{p1,p2},{p2,p3},...}, which can easily done with Partition. Then you can map Arrow over this list and have your result m = RandomInteger[{0, 10}, {5, 5}]; path = {{1, 1}, {2, 1}, {3, ...


12

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


12

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


12

You could mimic the panelled look by doing something like panelBox[pt0 : {x0_, y0_}, pt1 : {x1_, y1_}] := {{GrayLevel[.7], Rectangle[pt0, pt1]}, {White, Polygon[{Offset[{.3, .3}, pt0], Offset[{2, 2}, pt0], Offset[{2, -2}, {x0, y1}], Offset[{-2, -2}, {x1, y1}], Offset[{-.3, -.3}, {x1, y1}], Offset[{.3, -.3}, {x0, y1}]}]}, {GrayLevel[.2], ...


12

In the old days, when "making the Numerator rational" was often wanted, I came up with the following set of rules: EvaluiereAt[pos:(_Integer|{__Integer}),f_:Identity][expr_]:= ReplacePart[expr,pos->Extract[expr,pos,f]]; EvaluiereAt[pos:{{__Integer}..},f_:Identity][expr_] := Fold[ReplacePart[#1, #2 -> Extract[#1, #2, f]] &, expr, ...


12

<<19>> or Skeleton[19] means that some output (here 19 elements) is omitted. See the ShortAndShallowOutput tutorial in the Documentation Center for more information.


12

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


11

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


11

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"] ];


11

Mathematica does not have a built-in equivalent to sprintf. The closest thing is StringForm which allows placeholders within a string to be replaced, but does not perform any formatting of the replacement values: sprintf[control_, args___] := StringForm[control, args] // ToString sprintf["hello, ``", "Joe"] (* "hello, Joe" *) It is not pretty, but we ...


11

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 }


11

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


11

You can use the TableHeadings option to supply the row and column headings (which can also be images). Here's an example (data is the matrix in your question): lena = ImageResize[ExampleData[{"TestImage", "Lena"}], {64, 64}]; TableForm[With[{min = Min[#]}, # /. min -> Style[min, Red]] & /@ data, TableHeadings -> {ConstantArray[lena, 3], ...


11

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


11

The None option is the default, and is only for use when applied to all datasets as one: ListPlot[Table[n^(1/p), {p, 4}, {n, 10}], Joined -> True, PlotMarkers -> None] You can use "", Null or Spacer[0] for the result you require.


11

I don't know if it qualifies as an answer to your question if I suggest to change the structure of the labeling in the first place. As you write it, the m is -- from the rendering point of view -- treated as a symbol, if you inclose it with quotation marks it will be treated as a string and no auto-italic is performed at all. E.g.: PlotLabel -> "Test ...


11

This works nicely: L[f_, a_, b_] := HoldForm[Integrate[#, {\[FormalX], a, b}]] &[f[\[FormalX]]] Note that I used \[FormalX] to prevent conflicts with the usual x, which may have had a previous definition. Try L[E^-Sqrt[#] &, 0, 1] with this definition:


11

One way to do this is: Sin[x]^8 + 2 Cos[x]^8 - 1/2 Cos[2 x]^2 + 4 Sin[x]^2 == 0 /. Solve[t == Cos[2 x], x] //FullSimplify // Expand // Union // Column // TraditionalForm It gives exactly your answer if you get rid of your denominator 16 (multiply both sides of your equation by 16). This will also work with more complex substitutions (for example t ...


11

A simple way is to use a ColorSetter. Where color is the color you want to display, run DynamicSetting@ColorSetter@color You can also copy the result and use it as input in a notebook. Illustration:


11

Use a combination of Hold and special Forms to do this: MakeBoxes[MyForm[expr_], form_] := MakeBoxes[expr, form] MakeBoxes[MyForm[Power[x_, p_ /; p < 0]], form_] := SuperscriptBox[MakeBoxes[x, form], MakeBoxes[p, form]] Attributes[doubleShow] = {HoldFirst}; doubleShow[expr_] := Module[{}, Print[MyForm //@ HoldForm[expr]]; Simplify[expr]] Resulting ...



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