Hot answers tagged output-formatting
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 ...
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
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
<<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
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 ...
11
Specify the display format of something using MakeBoxes, like so:
MakeBoxes[polarForm[z_Complex], form_] :=
With[{r = Abs[z], ϕ = Arg[z]},
RowBox[{If[r == 1, Sequence @@ {}, MakeBoxes[r, form]],
If[ϕ == 0, Sequence @@ {},
SuperscriptBox[MakeBoxes[E, form],
RowBox[{MakeBoxes["\[ImaginaryI]", form],
If[ϕ == 1, Sequence @@ {},
...
10
You can force the Column to display correctly in text-only script mode by passing it explicitly to OutputForm. For example:
#!/Applications/Mathematica.app/Contents/MacOS/MathematicaScript -script
list = {a, b, c};
Print[Column[list] // OutputForm];
gives the output you expect:
a
b
c
10
A standard approach for this kind of task uses Eliminate. It works nicely with polynomial equations, and even though neither this transformation : $\;\sqrt{5x - 1}-\sqrt{5-2x} \rightarrow t \quad$ nor the original equation : $ (26-x)\sqrt{5x-1} -(13x+14)\sqrt{5-2x} + 12\sqrt{(5x-1)(5-2x) }= 18x+32\quad$ are of polynomial types, nevertheless we can make some ...
10
Two possible answers.
TexForm converts a Mathematica expression into something you can use to paste it in TeX:
TeXForm[x/Sqrt[5]]
==> \frac{x}{\sqrt{5}}
A usually more convenient way of achieving this is right-clicking output, and selecting Copy as | LaTeX.
If all you're looking for is a neater display form inside Mathematica, then have a look at ...
10
You can use ToString and StringJoin to "correct" your approach as in my comment above. Another possibility of displaying it without using strings (my preferred way) is:
Outer[HoldForm[#1 #2 ] == #1 #2 &, #, #] &@Range@9 // TableForm
10
The result you're after is only correct in the reals. Since Mathematica generally assumes that everything is complex, I'm not sure if there is a simple way to make it return the result you want.
You can go backwards and check that, for $x\in\mathbb{R}$, $\frac{d}{dx}\log|x|=\frac1x$:
D[Log[Abs[x]], x]
FullSimplify[%, x \[Element] Reals]
(*
==> ...
10
Instead of SetOptions, it is also possible to use CurrentValue. In this particular case the syntax is
CurrentValue[$FrontEnd, {RenderingOptions, "HardwareAntialiasingQuality"}] = 1.0
CurrentValue is easier to use than SetOptions in the situation when a single option has multiple sub options. If we have an option of the form opt -> {a -> 1, b -> ...
10
Here is a solution :
m = RandomInteger[{-5, 5}, {10, 10}];
m /. {x__, y_ /; y > 0} :> (Style[#, Red] & /@ {x, y});
% // TableForm
Explanation about TableForm[]
TableForm[] accepts as argument only a List[] of List[].
m /. {x__, y_ /; y > 0} ->
Style[{x, y}, Red] seems to be a List[] of List[] :
but in fact the red lines have ...
9
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])
9
It indeed seems that the thickness of the frame doesn't respond to any of the options in Frame. As a workaround, you could do this:
SetOptions[FrameBox, BoxFrame -> 3];
Framed["AA", FrameStyle -> Red]
However, the SetOptions will affect all frames drawn in your notebook (even ones that have been drawn before).
A more customizable approach would ...
9
Simplest solution I think would be just using ParametricPlot3D. For other techniques please see this questions:
Plotting several functions
Using ListPointPlot3D to simulate 2D plots moving in time
Now let's look at specifically to your examples and ParametricPlot3D.
Your 1st example can be simplified a bit:
sol = DSolve[{y''[t] + y'[t] + y[t] == 3 ...
9
A bit different approach :
Simplify @ TrigReduce[ Sin[x]^8 + 2 Cos[x]^8 - 1/2 Cos[2 x]^2 + 4 Sin[x]^2 == 0
/. Solve[ t == Cos[2 x], x, InverseFunctions -> True][[1]]]
35 + 10 t^2 + 4 t^3 + 3 t^4 == 28 t
or using Eliminate :
Eliminate[ TrigToExp[{ Sin[x]^8 + 2 Cos[x]^8 - 1/2 Cos[2 x]^2 + 4 Sin[x]^2 == 0,
t == Cos[2 x]}], x, ...
9
Perhaps I am missing the subtlety of your formatting needs but I think you can make this a lot simpler.
With your two column table as dat try:
Grid[
dat ~Partition~ 20 ~Flatten~ {{2}, {1, 3}},
Dividers -> {{All, {3 -> Thick, 5 -> Thick}}, All},
Alignment -> {{{Right, Left}}, Center},
Spacings -> {{{1, 0.5}}},
BaseStyle -> ...
8
Take a look at this blog post by Jon McLoone:
Automatic Physical Units in Mathematica
where he explains how to use this package:
Automatic Units
which has over 1000 physical units. Also you can simply use Wolfram|Alpha integration in Mathematica. At the beginning of any input line type single equal sign and see it turn into a large orange equal sign, - ...
8
It really does not matter how to write these equation - the order does not influence mathematical statement. Your both cases are correct mathematically. Notation/style is a different matter. Use transition to traditional notation:
TraditionalForm[Simplify[w.n] == 0]
To get a better grip on the subject please read Polynomial Orderings.
8
An interesting problem.
Trivially one could use Print like this:
Print[2 + 2, Spacer[50], "this is a note"]
4 this is a note
But that is hardly a usable syntax. Looking deeper into the system one observes that (* comments *) are stripped during parsing so those are out of reach without prohibitive contortions. Strings however are inert objects ...
8
There are several issues here. You need to "inject" the symbol name into the expression using With (or similar) to prevent trying to make an assignment to ToExpression["col" <> ToString[i]]. Further, you've got spurious Background -> expressions which do not belong. (I also use Symbol in place of ToExpression.) That gives us:
...
8
Here is an approach that doesn't rely on undocumented features or on low-level box manipulations. We're dealing with a polynomial, so we can simply collect its coefficients and arrange them any way we like as follows:
c0 = Collect[(1 + x + Cos[s] x^2)^3, x];
cx = CoefficientList[c0, x] x^Range[0, Exponent[c0, x]]
(*
==> {1, 3 x, x^2 (3 + 3 Cos[s]), x^3 ...
8
Depending on what you are doing, this might be better solved by using Graphics commands and building the display as a graphics object rather than a textural output. This however does the trick with just inserting elements into the grid shape:
gridDots[a_] := Module[{
rowspacing = Riffle[#, " ", {1, 1 + Last@Dimensions[a] 2, 2}] &,
colspacing = ...
8
This is a nice exercise on boxing:
MakeBoxes[u[v_[r_[b_]]], TraditionalForm] :=
Module[{b1, b2, b3, t},
t = ToBoxes[#, TraditionalForm] &;
{bl1, bl2, bl3} =
StyleBox[#1, #2] & @@@ { {"{", {20, Orange}}, {"[", {15,
Purple}}, {"(", {12, Blue}}};
{br1, br2,
br3} = {bl1, bl2, bl3} /. {"[" -> "]", "{" -> "}", "(" -> ")"};
...
8
I believe the following should work:
SetOptions[$FrontEnd, RenderingOptions -> {"HardwareAntialiasingQuality" -> 1}]
for a permanent global setting,
SetOptions[$FrontEndSession, RenderingOptions -> {"HardwareAntialiasingQuality" -> 1}]
for a temporary (session duration) global setting, and
SetOptions[EvaluationNotebook[], RenderingOptions ...
8
The * multiplication operator is rendered in InputForm:
c = a*b;
c // InputForm
a*b
For producing/exporting strings:
ExportString[c, "Text"]
ToString[c, InputForm]
"a*b"
"a*b"
Only top voted, non community-wiki answers of a minimum length are eligible






