wolfram-mathematica

Update (reload) mathematica package after changes

落花浮王杯 提交于 2019-12-04 17:31:45
问题 I'm trying to find a shortcut to the following loop. When developing a mathematica's package one is implementing changes to the .m file's code and then want to test the changes in another notebook. This is an infinite loop... So, we have a package package.m and a notebook test_package.nb where testing is done. Currently, when ever I change something in the .m file, I then have to: Quit[] Needs["package`"] in the notebook for the changes to become available, so I can test them. It seems like

Mathematica's pattern matching poorly optimized?

杀马特。学长 韩版系。学妹 提交于 2019-12-04 17:10:00
问题 I recently inquired about why PatternTest was causing a multitude of needless evaluations: PatternTest not optimized? Leonid replied that it is necessary for what seems to me as a rather questionable method. I can accept that, though I would prefer a more efficient alternative. I now realize, which I believe Leonid has been saying for some time, that this problem runs much deeper in Mathematica , and I am troubled. I cannot understand why this is not or cannot be better optimized. Consider

Entering data with Input[] in mathematica

社会主义新天地 提交于 2019-12-04 16:51:02
How can i make in this code the text in Dialog Box of the Input command to be like this "Enter the 1 element","Enter the 2 element".... For[k = 1, k ≤ n, k++, br = Input["Enter the ",i,"element"]; AppendTo[x, br]; ] Make sure your variables match. :-) You can use Row to build up the text. x = {}; n = 3; For[k = 1, k <= n, k++, br = Input[Row[{"Enter the ", k, " element"}]]; AppendTo[x, br]; ] (You could also use StringJoin["Enter the ", ToString[k], " element"] , but I like Row better.) According to the Input[ ] help: The prompt given can be text, graphics or any expression. So, anything will

Vertical alignment of plots in mathematica via GraphicsColumn

回眸只為那壹抹淺笑 提交于 2019-12-04 16:04:21
I have an annoying problem using GraphicsColumn() in Mathematica to combine several DateList plots in a single column. I need them to be correctly aligned as they display different timeseries for the same period, but as it turns out the size of the frame of each plot gets automatically resized depending on the length of the Y-axis labels. So combining a plot with 5-figure labels and one with 2-figure labels will totally jeopardise the vertical alignment. I tried several tweaks (e.g. setting width or max width via ImageSize), unfortunately they all seem to apply to the size of the graphic as a

Symbolic Conditional Expectation in Mathematica

怎甘沉沦 提交于 2019-12-04 15:45:14
I want to implement the conditional expectation operator. I will use the capital epsilon E to denote the operator. I expect at least the following input (underscore means subscript) E_2[a] E_2[x_1] E_2[x_1 + y_5] E_1[3 a + b - 4 + 2 x_] E_6[x_5 x_7] E_t[x_t] E_t[3 x_{t - 1} x_{t + 2}] to produce the following output a x_1 E_2[y_5] + x_1 -4 + 3 a + b + 2 E_2[x_5] E_6[x_7] x_5 x_t 3 E_t[x_{t + 2}] x_{t - 1} The examples above are not the only input/output pairs I need to produce, but rather serve as a test and an illustration for the syntax I prefer. I've got this far. ce means Conditional

Caching of data in Mathematica

廉价感情. 提交于 2019-12-04 15:38:28
there is a very time-consuming operation which generates a dataset in my package. I would like to save this dataset and let the package rebuild it only when I manually delete the cached file. Here is my approach as part of the package: myDataset = Module[{fname, data}, fname = "cached-data.mx"; If[FileExistsQ[fname], Get[fname], data = Evaluate[timeConsumingOperation[]]; Put[data, fname]; data] ]; timeConsumingOperation[]:=Module[{}, (* lot of work here *) {"data"} ]; However, instead of writing the long data set to the file, the Put command only writes one line: "timeConsumingOperation[]",

Solving Matrix Differential Equation in Python using Scipy/Numpy- NDSolve equivalent?

江枫思渺然 提交于 2019-12-04 14:38:32
I have two numpy arrays: 9x9 and 9x1. I'd like to solve the differential equation at discrete time points, but am having trouble getting ODEInt to work. I do am unsure if I'm even doing the right thing. With Mathematica, the equation is: Solution = {A[t]} /. NDSolve[{A'[t] == Ab.A[t] && A[0] == A0}, {A[t]}, {t, 0, .5}, MaxSteps -> \[Infinity]]; time = 0.25; increment = 0.05; MA = Table[Solution, {t, 0, time, increment}]; Where Ab is the 9x9 matrix, A0 is the 9x1 matrix (initial). Here, I solve for time and life is good. In Python implementation I have the following code which gives me the

$Assumption for multiple variables

五迷三道 提交于 2019-12-04 13:44:36
I want to restrict my variables to certain ranges for my entire notebook, is there a way I can do that in one go without entering a different $assumption line for every variable? Edit: I want to define the domain of variables for all calculations in my notebook (googling helped me frame my needs better!) If all of your variables are going to be (for example) Real , then you can intercept the creation of new symbols and add that assumption to $Assumptions . E.g. $Assumptions = True; $NewSymbol = If[#2 === "Global`", Print["Created new Global` variable named ", #1, ". It is assumed to be real."]

How to enable Mathematica syntax highlighting for MediaWiki using extension “SyntaxHighlight GeSHi”?

时光毁灭记忆、已成空白 提交于 2019-12-04 12:58:49
I'd like to syntax highlight Mathematica code on a MediaWiki site. I've already installed the MediaWiki extension SyntaxHighlight GeSHi and verified that it works for other languages. I tried simply putting a Mathematica langauge data file mathematica.php into MediaWiki's extension path wiki/extensions/SyntaxHighlight_GeSHi/geshi , however it didn't correctly highlight a Mathematica code block such as: <syntaxhighlight lang="Mathematica"> (* this is a comment *) List[Sin[x], Cos[x], Tan[x]]; </syntaxhighlight> Any ideas? I do not see Mathematica listed as a supported language at http://qbnz

Define control as variable in Mathematica

牧云@^-^@ 提交于 2019-12-04 12:51:51
问题 When I use Manipulate I can do: Manipulate[x, {u, 1, 10}] In reality my controls are many and complicated, so I would prefer to take their definition out of the Manipulate expression, like that: control = {u, 1, 10} Manipulate[x, control] But that does result in a an error: Manipulate argument control does not have the correct form for a \ variable specification. Why doesn't it work that way? 回答1: Manipulate has the HoldAll attribute. You can force control to evaluate and everything works ok