Hot answers tagged

15

The output from Information[] gets sent to the $Urgent stream. Here is how you can capture it: infoFile = OpenWrite["info.txt", FormatType -> OutputForm, PageWidth -> Infinity] Block[{$Urgent = infoFile}, Information["DSolve", LongForm -> False] ] Close[infoFile] Note that I used PageWidth->Infinity. This results in possibly (?) cleaner ...


13

I believe it does work, just not how you expect. :-) From the documentation for PutAppend: Note that there are no quotation marks around filename in the first line. It is not made particularly clear but you can use this syntax with >>>: Range[10] >>> file.txt Which outputs to a file named file.txt directly. This is a special and ...


11

I consider this a bug in the front end. Very odd it is, that not all forms eat up the first result. Consider this simple example m = {1}; MatrixForm@m MatrixForm@m which gives 2 outputs as expected. If we look on the traffic between kernel and front end, then we see, that the kernel indeed sends 2 outputs back. No matter which kind of form we use: FE ...


11

A more general way, which can be used for other functions like Solve, is to use Normal. Integrate[1/x^s, {x, 1, Infinity}] (* ConditionalExpression[1/(-1 + s), Re[s] > 1] *) Normal[%, ConditionalExpression] (* 1/(-1 + s) *) Edit It looks like as of version 10, one can just use the one argument Normal: Integrate[1/x^s, {x, 1, Infinity}] (* ...


10

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


10

The question is, what do you want to do with the output. The output of Position is in a form so that it can directly be used with Extract list = {a, b, a, a, b, c, b}; pos = Position[list, b]; Extract[list, pos] (* {b, b, b} *) For this simple example, it is a bit useless because we already know, that on all positions pos we have a b in list. ...


10

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


10

On Windows, MathKernel.exe launches the kernel running within a window. The standard output is redirected to that window. To avoid this redirection, we must run the kernel as a console application using Math.exe instead: "C:\Program Files\Wolfram Research\Mathematica\10.0\Math" ^ -noprompt ^ -script C:\Users\a\Desktop\test.m ^ "data goes here" ...


9

If you examine the Cell expressions (select the cell and hit ctrl-shift-E) you can see that in the first case the lines are separated by \n whereas in the second case [IndentingNewLine] sneaks in (I pasted the second case and hit return between the lines as it pasted as a single line). It would appear that [IndentingNewLine] doesn't count as an input ...


9

You have several possibilities: 1) Instead of Printing into usual StandardForm Cell where the parsing and 2D formatting take significant processor's time you can print into plain text Cells: CellPrint[Cell["stuff=" <> ToString[stuff]]]] This takes substantially less CPU time and should render much faster. 2) Instead of printing into separate cells ...


9

The reason is that you have empty history because you set $HistoryLength = 0 (as you confirm in the comments). I recommend setting $HistoryLength to be at least 3 in order to get the [Show Full Output] button working in the most practical cases.


8

As suggested by many (@YvesKlett, @acl) you can use Export : output2 = Flatten[Table[{x[[i]], y[[ j]], z[[k]], x[[i]] + y[[j]] + z[[k]]}, {i, 1, 3}, {j, 1, 3}, {k, 1, 3}], 2] ; Export["test.tsv", output2]


8

If you make any assumptions you have to share them with Mathematica as well. For Example: Assuming[R > 0, FullSimplify[(R^3)^(1/3)]] (*R*) The default assumption is that all variables are complex. (As @J.M. noted in the comments).


8

As already explained, this happens because MatrixForm act as a wrapper. The answer to the question about how this behavior is implemented and how can eventually be reproduced is contained in the Informmation of the system symbol $OutputForms. Indeed ?? $OutputForms returns: $OutputForms is a list of the formatting functions that get stripped off ...


8

To summarize the comments into an answer: The second element is a list of lists because there may be several different tags sown. For example, Reap[Sow[1, x]; Sow[2, y]; result] (* {result, {{1}, {2}}} *) Another example by belisarius, Reap[Sow[1, {x, y}]; Sow[2, y]; Sow[3, x], _, tag] (* {3, {tag[x, {1, 3}], tag[y, {1, 2}]}} *) See also this ...


8

This is not a bug. It is an expected result of numerical roundoff error and the somewhat unusual way Mathematica computes division. What is roundoff error? Floating point numbers have a finite precision. With almost any arithmetic operation performed, the result is not exact: digits beyond about the 16th get discarded. What's special about how ...


7

I have found one solution, using a temporary file:- streams = AppendTo[$Output, OpenWrite[]]; Module[{}, Print[Plot[Sin[x], {x, 0, 2 Pi}]]; a = 123]; Close@Last@streams; $Output = Most@streams; printoutput = ReadList@First@Last@streams


7

(This answer doesn't include how to make it fullscreen, I can't manage to get any window at all to fullscreen without going through my window manager) With DisplayFunction -> (CreateDialog[#, WindowMargins -> {{1, Automatic}, {Automatic, 1}}]&) you can get it in the top left corner, however it will be on the main display. From WindowMargins: ...


7

Like Mike said in a comment, the key is to use the second argument of Dynamic. In this case I've built a function updateCurrencies which modifies a global variable currencies which holds an Association object with all the currency values in it. currencies = <| "USDollars" -> 0, "Euros" -> 0, "BritishPounds" -> 0, "SwedishKronor" ...


7

NonlinearModelFit returns a FittedModel object. Please see the respective documentation pages on how to use these objects. Most importantly: these objects contain a lot of information that is not meant to be read by you, the user. What you see on the screen is just a shorthand representation of the object. In most cases, you cannot copy this visual ...


6

I'll assume that you want to echo any literal Set operation that occurs in input, even if it is not on a line by itself. $Pre This may work for you: $Pre = Function[ main, Unevaluated[main] /. Set -> Function[, Print@HoldForm[# = #2]; # = #2, HoldFirst], HoldAll ]; Now: {a = 2 + 2, b = 10/2, c = Sqrt[9]}; a = 4 b = 5 c = 3 ...


6

You can use GenerateConditions->False to eliminate conditions (assuming they do not affect your planned use): S[x_, l_] := (C[1] + Integrate[ E^(2 Sum[t^i/i, {i, 1, l - 1}]) (1 - t)^2* Sum[(l - i*2) t^i, {i, 1, l - 1}]/((t - 1) t^l), {t, 1, x}, GenerateConditions -> False]) x^(l - 1)* E^(-2 Sum[x^i/i, {i, 1, l - 1}])/(1 - ...


6

"MatrixForm acts as a "wrapper", which affects printing, but not evaluation. " The output returned by % or Out[] is the result obtained prior to applying the wrapper. It is important to note this behavior is pecular to the assignment to the output history. For example: m = mat // MatrixForm actually assigns the MatrixForm to m (Note this is a ...


6

I propose: a = {1, 4, 11, 14}; b = Range[0, 14]; {#, Pick[b, Mod[b (1 + #), 15], 0]} & /@ a { {1, {0}}, {4, {0, 3, 6, 9, 12}}, {11, {0, 5, 10}}, {14, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}} } Anything more is formatting, which I shall leave to you.


6

I am not familiar with this function but based on your example there is some relation to SpokenString, e.g. gr = Graphics[{Thick, Green, Rectangle[{0, -1}, {2, 1}], Red, Disk[], Blue, Circle[{2, 0}], Yellow, Polygon[{{2, 0}, {4, 1}, {4, -1}}], Purple, Arrowheads[Large], Arrow[{{4, 3/2}, {0, 3/2}, {0, 0}}], Black, Dashed, Line[{{-1, 0}, {4, 0}}]} ...


5

One way to do this is to define the solution as sol = Solve[b^2 + b*z + 1 == 0, b][[1]]; and then plot using the strategy suggested in the Help file for Solve, which replaces the variable in the rule (in this case b) with the desired solution: Plot[b /. sol, {z, -10, 10}, PlotRange -> All]


5

You can temporarily redefine Print, like so: fun[] := Module[{}, Print[Plot[Sin[x], {x, 0, 2 Pi}]]; a = 123] list = {}; Block[{Print = AppendTo[list, {##}] &}, fun[]] Now list contains everything that was printed. (Of course in a practical application you'd probably want to do something smarter than an inefficient periodic AppendTo) If you still ...


5

It's just not always true that $(R^3)^{1/3} = R$. How about $R=i$, for example? N[(I^3)^(1/3)] (* Out: 0.866025 - 0.5 I *) If you expect this, you might have more luck with the real-valued CubeRoot function. For example: FullSimplify[CubeRoot[R^3]] (* Out: R *)


5

The following works for me output = OpenWrite["C:\\Users\\Mike Croucher\\outtest3.txt", FormatType -> OutputForm]; $Output = output Print["hello"] Close[output]; I get the word 'hello' in outtest3.txt. However, the following does not work output = OpenWrite["C:\\Users\\Mike Croucher\\outtest4.txt", FormatType -> OutputForm]; $Output = output ...


5

I think I would choose to use MakeBoxes and Defer for this: MakeBoxes[a_^Rational[1, x_], fmt_] := ToBoxes[a^Defer[1/x], fmt] Now: -Sqrt[a - bar] -(a - bar)^(1/2) This also catches cases that use RadicalBox: x^(1/3) // TraditionalForm x1/3 Defer is used to allow the output to be used as input. An alternative is Interpretation but that ...



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