Tag Info

New answers tagged

1

The OP's basic approach seems to work for me, although the code for rss doesn't work because zcol etc. are arrays, not functions. Assuming you want the sum of squares of the residuals, here is an example fix: {xcol, ycol, zcol} = RandomReal[{-10, 10}, {3, 20}]; Clear[DefineRSS]; DefineRSS[a_?NumericQ, b_?NumericQ, c_?NumericQ] := ( rss = Total[(zcol - ...


2

I decided to edit the title and answer this question as wiki because I think it is not easy for new users to find this kind of information. The more if they are not aware of special handling of ? ! in search fields. So the explanation of things like: \!\(TraditionalForm\` c (1 + x)\) is in the tutorial String Representation of Boxes. Here are ...


2

If I understand well, what you probably need is first Pane (with its ImageSize option) then Framed. What about this : expr1 = a x^2 + b x + c; expr2 = expr1/d; fixedframe[expr_]:=Framed@Pane[Style[TraditionalForm[expr1], 16], ImageSize -> {200, 50}, Alignment -> Center] then fixedframe[expr1] fixedframe[expr2] The size of the frame ...


2

Simple: use Table Sum[i^2, {i, 3}] (* 14 *) Table[i, {i, 3}] (* {1, 4, 9} *) If you want the output to be displayed like a sum, use Row: Row[%, "+"] (* 1 + 4 + 9 *) And when you want to evaluate, simply use Total: Total[%%] (* 14 *) There is another solution (see David's comment): Sum[(HoldForm[#] &)[i^2], {i, 3}] (* 1 + 4 + 9 *) To explain ...


1

A look at the FullForm motivates e.g. this: der = Derivative[1, 0, 0][f][x, y, z]/Derivative[1, 0, 0][h][x, y, z]; der /. Derivative[a___][b___][c___] :> Derivative[a][b]


2

Select the cell containing your output, then choose TraditionaForm from the Convert To submenu of the Cell menu. The cell will then show Update Perhaps this is what you are looking for: (f^(1,0,0))[x, y, z]/(h^(1,0,0))[x, y, z] /. h_[x, y, z] -> h


8

You can also use MapAt with Invisible or Style[#,White]&: f1 = MatrixForm[MapAt[Invisible, #, Position[#, Except[#2], {2}, Heads->False]]] &; (* or f1 = MatrixForm[MapAt[Style[#,White]&, #, Position[#, Except[#2], {2}, Heads->False]]] &; *) Example: m = RandomInteger[5, {5, 5}]; Row[Prepend[f1[m, #] & /@ {1, 2, 1 | 2}, ...


5

Here's a variation you might find useful: fn[a_?ArrayQ, x_] := Replace[a, p : Except[x] :> Style[p, White], {ArrayDepth@a}] // MatrixForm Now: fn[IdentityMatrix[3], 1] But because the non-selected elements are only styled white they appear when selected:


5

f[x_List, n_] := (x /. y_ /; y != n -> " ") // MatrixForm f[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, 7] If you need to display only elements in list n, then use: g[x_List, n_List] := x /. y_ /; (MemberQ[Complement[Flatten[x], n], y]) -> " " // MatrixForm g[{{1,2,3},{4,5,6},{7,8,9}}, {3,7}] I'm sure there's a more elegant way to do this last ...


1

If you are trying to place each grid into a separate cell, change the last line to this: Scan[Print, Array[grid @ block @ # &, 4]] or this: Print ~Scan~ Array[grid@block@# &, 4] or this: Array[grid@block@# &, 4] // Scan[Print, #]& ... as suits your taste. Mathematica version 10 allows this nice-looking alternative form: Array[grid ...


4

New answer Here is a modularized method. The first function is from Trying to write out the prime factorization of a number with CenterDot and Superscript, slightly modified. Format[primeFactorForm[n_Integer]] := Times @@ Superscript @@@ FactorInteger[n] /. _[x_] :> x block[n_Integer] := Join @@@ Array[{#, primeFactorForm@#} &[# + 16*#2] ...


1

Using Position with MapAt: ClearAll[sF]; sF = With[{pos = Thread[{Range@Length@#, Position[#, Max@#][[1, 1]] & /@ #}]}, MapAt[Style[#, Bold, Red] &, #, pos]] &; t = Table[i/j + 4*Boole[j > i] // N, {i, 3}, {j, 4}]; h = {{"Row1", "Row2", "Row3"}, {"Col1", "Col2", "Col3", "Col4"}}; TableForm[sF@t, TableHeadings -> h] ... with ...


3

Yet another realization of the straightforward idea t = Table[i/j + 4*Boole[j > i] // N, {i, 3}, {j, 4}]; h = {{"Row1", "Row2", "Row3"}, {"Col1", "Col2", "Col3", "Col4"}}; Style[TableForm[# /. x : Max@# :> Style[x, Bold] & /@ t, TableHeadings -> h], FontFamily -> "Times"] I change FontFamily for better visibility


2

TableForm[ (m = Max[#]; (# /. m :> Style[m, Red] ) ) & /@ Table[i/j + 4*Boole[j > i] // N, {i, 3}, {j, 4}] , TableHeadings -> {{"Row1", "Row2", "Row3"}, {"Col1", "Col2", "Col3", "Col4"}}] Red is easier to see but Bold works as well..


2

Maybe the simplest method is CForm with small string postprocessing moodleForm[expr_] := StringReplace[#, {"power" -> "pow", "md(" ~~ Shortest@x__ ~~ ")" :> "{" ~~ x ~~ "}"}] &@ ToLowerCase@ToString[#, CForm] &@Simplify[expr, Assumptions -> _md ∈ Reals] StandardDeviation[{md[a], md[b], md[c]}] // moodleForm (*sqrt(pow({a},2) + ...


1

It is possible to change the style used for output with this Front End option: "GeneratedCellStyles" -> {"Output" -> (* style *)} One can change this style as part of the output formatting routine using $PrePrint, like this: defaultOut[] := SetOptions[EvaluationNotebook[], "GeneratedCellStyles" -> {"Output" -> "Output"}] altOut[] := ...


3

For Graphics output specifically there is a nice approach using $DisplayFunction: (* create a new output style -- overwrites existing custom style sheet *) SetOptions[EvaluationNotebook[], StyleDefinitions -> Notebook[{Cell[StyleData[StyleDefinitions -> "Default.nb"]], Cell[StyleData["altOutput"], TextAlignment -> Center]}, ...


7

Version 10 introduced some undocumented functionality that makes it easier to explore the style hierarchy. As usual, "undocumented" === "buyer beware". We start by evaluating: StyleManager`OpenStyleManager This does nothing other than trigger the auto-loading of certain symbols. We'll come back to a more interesting use of this symbol later. Now, we ...


3

An alternative is to use $Post to post-process output automatically as it is generated. For instance, the following outputs anything with the head Graphics in a style "centeredOutput", which could be defined in whatever manner one wants. centerGraphics[g_Graphics | g_Graphics3D] := CellPrint@ExpressionCell[g, "centeredOutput"]; centerGraphics[x_] := x; ...


5

If you want to do it all programmatically you could import the notebook containing the cells with graphics and change the cell style for cells containing graphics: changeStyle[file_String, newStyle_String] := Module[{nb = NotebookOpen[file], nb1}, nb1 = NotebookGet[nb]; NotebookClose[nb]; nb = nb1 /. (p1 : Cell[BoxData[GraphicsBox[_, ___]], ...



Top 50 recent answers are included