wolfram-mathematica

Exporting Mathematica Print[] Output to a .txt file

房东的猫 提交于 2019-11-30 06:41:50
I have a large Mathematica notebook that uses Print[] commands periodically to output runtime messages. This is the only output (aside from exported files) that this notebook generates. Is there any way I can automate the export of this output to a .txt file without having to re-write the Print[] commands? rcollyer According to the documentation , Print outputs to the $Output channel which is a list of streams. So, at the beginning of the notebook, strm = OpenWrite["output.log"]; AppendTo[ $Output, strm ]; and at the end of the notebook Close[strm]; Note, if execution is interrupted prior to

Integrating notebooks to Mathematica's documentation center

你离开我真会死。 提交于 2019-11-30 06:09:33
问题 If you have been using Mathematica for a while you probably have grown attached to the documentation center. There is always something new that you find in those pages. Let it be options for a function or just some examples that at some point did not seem useful to you. It is likely that you have written packages with your specialized functions that you use all the time. Sometimes you might think of a neat example to use with your function but it is likely that it ends up being forgotten

Performance of Fibonacci

南楼画角 提交于 2019-11-30 05:20:08
问题 f[0] = 0; f[1] = 1; f[x_] := f[x-1] + f[x-2] This function is running slow in Mathematica and I need to increase the speed. I have to use functional programming and recursion. I'm not sure why this is running so slow, and even the slightest idea how to improve this would be helpful. 回答1: A good way to write a faster recursive function is to have it memorize previous values. This does come at the cost of memory, of course, but it can help in cases like this. In order to calculate f[x] , you

CounterIncrements for individual cells

末鹿安然 提交于 2019-11-30 04:58:14
问题 This post derives from my question extending cell definition to cellframelabels. I've been playing around with CounterIncrements and I'm not obtaining what I'm expecting. As Simon did in his answer to the post I mentioned we start by producing a counter. CellPrint[Cell["Setting the counter", "Text", CounterAssignments -> {{"MyCounter", 0}}]] Now we print this counter. CellPrint[Cell[ TextData[RowBox[{"MyCounter ", CounterBox["MyCounter"]}]], "Text"]] The result of this will be: MyCounter 0 To

Reading an UTF-8 encoded text file in Mathematica

别等时光非礼了梦想. 提交于 2019-11-30 04:57:44
How can I read a utf-8 encoded text file in Mathematica? This is what I'm doing now: text = Import["charData.txt", "Text", CharacterEncoding -> "UTF8"]; but it tells me that $CharacterEncoding::utf8: "The byte sequence {240} could not be interpreted as a character in the UTF-8 character encoding" and so on. I am not sure why. I believe the file is valid utf-8. Here's the file I'm trying to read: http://dl.dropbox.com/u/38623/charData.txt Short version: Mathematica's UTF-8 functionality does not work for character codes with more than 16 bits. Use UTF-16 encoding instead, if possible. But be

Convenient way to add inline formatting to usage Messages

随声附和 提交于 2019-11-30 04:48:29
问题 Usage Messages of built-in functions have embedded in-line formatting. For example: In[1]:= ActionMenu::usage // FullForm Out[1]//FullForm= "\!\(\*RowBox[{\"ActionMenu\", \"[\", RowBox[{StyleBox[\"name\", \"TI\ \"], \",\", RowBox[{\"{\", \ RowBox[{RowBox[{SubscriptBox[StyleBox[\"lbl\", \"TI\"], \ StyleBox[\"1\", \"TR\"]], \":>\", SubscriptBox[StyleBox[\"act\", \"TI\ \"], StyleBox[\"1\", \"TR\"]]}], \",\", \ RowBox[{SubscriptBox[StyleBox[\"lbl\", \"TI\"], StyleBox[\"2\", \ \"TR\"]], \":>\",

Can the frame border on a BarChart Legend be removed?

让人想犯罪 __ 提交于 2019-11-30 04:27:20
问题 I am creating an application for various kinds of plot/chart drawing in Mathematica. Ultimately it will have a GUI, but the first step is to get the code right, and simple enough for a GUI to manage. I am having difficulty setting legends to have no frame around them. Here is a minimal example (with some options on BarChart already customised using SetOptions . mydata = {4.5644, 5.546, 6.8674, 2.7688, 1.742, 5.3952, 4.3392, 4.5016, \ 3.7748, 1.838, 2.24, 0.693, 2.818, 4.9, 3.939, 3.459, 3.755

Generate a list in Mathematica with a conditional tested for each element

拟墨画扇 提交于 2019-11-30 03:52:23
Suppose we want to generate a list of primes p for which p + 2 is also prime. A quick solution is to generate a complete list of the first n primes and use the Select function to return the elements which meet the condition. Select[Table[Prime[k], {k, n}], PrimeQ[# + 2] &] However, this is inefficient as it loads a large list into the memory before returning the filtered list. A For loop with Sow/Reap (or l = {}; AppendTo[l, k] ) solves the memory issue, but it is far from elegant and is cumbersome to implement a number of times in a Mathematica script. Reap[ For[k = 1, k <= n, k++, p = Prime

Mathematica Overflow[] error : Why and how-to bypass?

被刻印的时光 ゝ 提交于 2019-11-30 03:42:48
问题 I never had an overflow error in Mathematica, the following happened. I demo-ed the principle of RSA-encryption as follows: n = 11*13 m = EulerPhi[n] e = 7 GCD[e, m] d = PowerMod[e, -1, m] cipher2[m_String] := Map[Mod[#^e, n] &, ToCharacterCode[m]] decipher2[x_Integer] := FromCharacterCode[Map[Mod[#^d, n] &, x]] In[207]:= cipher2["StackOverflow"] decipher2[cipher2["StackOverflow"]] Out[207]= {8,129,59,44,68,40,79,62,49,119,4,45,37} Out[208]= StackOverflow No problem sofar. Then I changed the

Getting CellDingbat to remember its state between Mathematica sessions

只谈情不闲聊 提交于 2019-11-30 03:27:51
问题 I have modified my notebook's stylesheet to include a StyleData["Todo"] that inherits from StyleData["Item"] . It changes the cell dingbat to a checkbox. In the stylesheet editor: Cell[StyleData["ToDo", StyleDefinitions -> StyleData["Item"]], CellDingbat->DynamicModuleBox[{$CellContext`color$$}, CheckboxBox[ Dynamic[$CellContext`color$$], {RGBColor[1, 0.5, 0],RGBColor[0,Rational[2, 3], 0]}, Background -> Dynamic[$CellContext`color$$]], DynamicModuleValues :> {} ], ] The problem is that the