wolfram-mathematica

Getting current context from within Package

寵の児 提交于 2019-12-08 03:06:28
问题 I had something like the following in my notebook. test1[g_] := (g == 5); test2[g_] := (g == 6); tests={"test1", "test2"} ToExpression[#][5] & /@ tests When I put this code in a package it doesn't work because test1 is now called MyPackage'Private'test1 . How can I modify the last line to make this code run both inside package and inside notebook? Update Here's why I was doing doing ToExpression as opposed to using Symbols. In retrospect, maybe it's easier to use Symbols instead I had a

Difference in eigenvector transformations: Mathematica vs. SciPy

笑着哭i 提交于 2019-12-08 00:55:49
问题 Similar questions have been asked previously here but none seem to answer my example. I compute the eigenvalues and eigenvectors of a matrix A using Mathematica and SciPy; the eigenvalues agree but this is not the case for the eigenvectors: (1) the lowest (eigenvalued) eigenvector agrees (2) the remaining corresponding eigenvectors of Mathematica and SciPy are not related by a multiplicative factor (3) I can compute the transformation matrix T sending SciPy's eigenvector to Mathematica's

Sum[] and Sequence[] in Wolfram Mathematica

可紊 提交于 2019-12-08 00:38:58
问题 I need to evaluate a sum over Cartesian product of variable number of sets. Assuming f[...] is a multivariate function, define p[A__set] := Module[{Alist, args, iterators,it}, Alist = {A}; i = 1; iterators = {it[i++], Level[#1, 1]} & /@ Alist; args = Table[it[i], {i, Range[Length[Alist]]}]; Sum[f@@ args, Sequence @@ iterators ] ] But then p[set[1, 2, 3], set[11, 12, 13]] Gives the error: Sum::vloc: "The variable Sequence@@iterators cannot be localized so that it can be assigned to numerical

posmax: like argmax but gives the position(s) of the element x for which f[x] is maximal

假装没事ソ 提交于 2019-12-07 23:23:58
问题 Mathematica has a built-in function ArgMax for functions over infinite domains, based on the standard mathematical definition. The analog for finite domains is a handy utility function. Given a function and a list (call it the domain of the function), return the element(s) of the list that maximize the function. Here's an example of finite argmax in action: Canonicalize NFL team names And here's my implementation of it (along with argmin for good measure): (* argmax[f, domain] returns the

Keyboard shortcut to quit kernel in Mathematica 5 and 7?

a 夏天 提交于 2019-12-07 22:46:47
问题 Here is an explanation how to define a custom keyboard shortcut for quitting the kernel of the selected notebook by modifying the file KeyEventTranslations.tr . This file is located by default (under Windows) for Mathematica 5.2 in the folder C:\Program Files\Wolfram Research\Mathematica\5.2\SystemFiles\FrontEnd\TextResources\Windows and for Mathematica 7.0.1 in the folder C:\Program Files\Wolfram Research\Mathematica\7.0\SystemFiles\FrontEnd\TextResources\Windows In this file after

How to check whether the FrontEnd considers evaluation still running?

断了今生、忘了曾经 提交于 2019-12-07 22:46:27
Is there a way to check programmatically whether the FrontEnd considers evaluation still running? Or even better: is there a way to check whether the FrontEnd has some pending inputs to be sent to the kernel? P.S. This question has arisen from previous question . EDIT When evaluating a Cell in the FrontEnd we usually create a queue of inputs for the kernel. I need a function that will return True if the FrontEnd has sent to the kernel the last input of the queue of inputs from the EvaluationNotebook[] . Or in other words I need a function that returns True if this current input is the last

Line Style using Graphics3D in Mathematica

冷暖自知 提交于 2019-12-07 18:01:57
问题 Consider the following : cAxes = {{{0, 0, 0}, {0, 0, 1}}, {{0, 0, 0}, {0, 1, 0}}, {{0, 0,0}, {1, 0, 0}}}; Graphics3D[{Line /@ cAxes}, Boxed -> False] How can Style differently the 3 lines ? 回答1: The answer above are good, but I want to show some alternatives. I show that it is possible to use Style for this, and that Tube is an interesting alternative to Line . cAxes = {{{0, 0, 0}, {0, 0, 1}}, {{0, 0, 0}, {0, 1, 0}}, {{0, 0, 0}, {1, 0, 0}}}; tubes = Tube@# ~Style~ #2 & ~MapThread~ {cAxes,

How to solve for the analytic solution of a recurrence relation in mathematica

时光毁灭记忆、已成空白 提交于 2019-12-07 16:58:00
问题 I have a recurrence such as following: RSolve[{f[m, n] == f[m, n - 1] + f[m - 1, n], f[0, n] == 1, f[m, 0] == 1}, f[m, n], {n}] I tried to use RSolve, but I got an error: RSolve::deqx: Supplied equations are not difference equations of the given functions. Appreciate your help! 回答1: The difference equation and initial conditions are Mathematica (7 and 8) does not like solving it... both with and without initial conditions. The RSolve expressions are left unevaluated In[1]:= RSolve[{f[m,n]==f

.NETLink Graphics producing PNG instead of EMF

早过忘川 提交于 2019-12-07 15:00:49
问题 The C# code below should produce an EMF, but viewing the output (in Vim) shows it to be a PNG. Perhaps someone on S.O. knows a good work-around or solution. MathKernel k = new MathKernel(); k.CaptureGraphics = true; k.GraphicsFormat = "Metafile"; k.Compute("Show[Graphics[{Thick, Blue, Circle[{#, 0}] & /@ Range[4], Black, Dashed, Line[{{0, 0}, {5, 0}}]}]]"); k.Graphics[0].Save("C:\\Temp\\file.emf", System.Drawing.Imaging.ImageFormat.Emf); So far I'm considering wrapping Show[Graphics...] in

Selecting data from a table in mathematica

馋奶兔 提交于 2019-12-07 14:23:08
问题 I'm trying to write a function that will take select the first element in the table that satisfies a criteria. For example, if I am given the following table with times in the first column and number of people infected with a disease in the second, I want to write an argument that will return the time where at least 100 people are infected. 0 1 1 2 2 4 3 8 4 15 5 29 6 50 7 88 8 130 9 157 10 180 11 191 12 196 13 199 14 200 So from this table, I want the arguemnt to tell me that at 8 seconds,