wolfram-mathematica

controlling order of variables in an expression

安稳与你 提交于 2019-11-29 11:42:54
In Mathematica, how do you change the order of importance of variables? for example: if i enter b+c+a+d, i get a+b+c+d but i want b and d to preceed other variables. so that i get b+d+a+c note, i'd like to use it where + is non-commutative First you need to define an ordering function like: In[1]:= CPOrdering[a]=3; CPOrdering[b]=1; CPOrdering[d]=2; CPOrdering[c]=4; Although, for more complicated examples, you should probably be smarter about it than this - ie use pattern matching. Then you can sort expressions using In[5]:= CirclePlus[a,b,c,d] SortBy[%,CPOrdering] Out[5]= a\[CirclePlus]b\

Install MathLink program with arbitrary PATH environment

时间秒杀一切 提交于 2019-11-29 10:56:09
Is it possible to use Install[] to start a MathLink program with a custom PATH environment variable? I am trying to use mEngine to connect Mathematica to MATLAB on Windows. It only works if mEngine.exe is launched when the PATH environment variable includes the path to the MATLAB libraries. Is it possible to modify the PATH for launching this program only , without needing to modify the system path? Or is there another way to launch mEngine.exe ? @acl's solution to wrap mEngine.exe in a batch file, and temporarily modify the PATH from there, works correctly: I used this as the contents of

Determine the position of a point in 3D space given the distance to N points with known coordinates

纵然是瞬间 提交于 2019-11-29 10:22:12
问题 I am trying to determine the (x,y,z) coordinates of a point p. What I have are the distances to 4 different points m1, m2, m3, m4 with known coordinates. In detail: what I have is the coordinates of 4 points (m1,m2,m3,m4) and they are not in the same plane: m1: (x1,y1,z1), m2: (x2,y2,z2), m3: (x3,y3,z3), m4: (x4,y4,z4) and the Euclidean distances form m1->p, m2->p, m3->p and m4->p which are D1 = sqrt( (x-x1)^2 + (y-y1)^2 + (z-z1)^2); D2 = sqrt( (x-x2)^2 + (y-y2)^2 + (z-z2)^2); D3 = sqrt( (x

new Graph in Mathematica 8.0

你。 提交于 2019-11-29 10:14:49
Has anybody figured out a way to modify Graph objects in Mathematica 8? In particular, how to get the same functionality you get when you right click on the graph. Some of the new graph functions conflict with Combinatorica , is there a way to force Mathematica to use a built-in version of the function? In other words, is there a way to get access to built-in CompleteGraph after I do Needs["Combinatorica"] which imports Combinatorica version of CompleteGraph ? To clarify 1, Context Menu on Graph lets you change GraphStyle and GraphLayout, and I'd like to be able to change them programmatically

Dynamic Programming in Mathematica: how to automatically localize and / or clear memoized function's definitions

醉酒当歌 提交于 2019-11-29 09:37:01
问题 In Mathematica 8.0, suppose I have some constants: a:=7 b:=9 c:=13 d:=.002 e:=2 f:=1 and I want to use them to evaluate some interlinked functions g[0,k_]:=0 g[t_,0]:=e g[t_,k_]:=g[t-1,k]*a+h[t-1,k-1]*b h[0,k_]:=0 h[t_,0]:=f h[t_,k_]:=h[t-1,k]*c+g[t-1,k-1]*d But this is really slow and in need of dynamic programming, or else you get an exponential slowdown: g[0, k_] := 0 g[t_, 0] := e g[t_, k_] := g[t, k] = g[t - 1, k]*a + h[t - 1, k - 1]*b h[0, k_] := 0 h[t_, 0] := f h[t_, k_] := h[t, k] = h

A Java advanced text logging pane for large output

老子叫甜甜 提交于 2019-11-29 09:28:13
Mathematica comes with a simple java program that allows to inspect the communication between front end and the kernel. It's called LinkSnooper and in general it works quite nice. It looks like this I think I can improve the behavior and usability of the program to some extend, but to do this, I need to reimplement some parts. One fundamental piece that I need is a text pane, which has the following properties: it can receive a lot of data and it probably should use a fast ring-buffer so that the very first log-lines are removed when the data grows too much. Another possibility is that it

Memory use of Apply vs Map. Virtual memory use and lock-ups

时间秒杀一切 提交于 2019-11-29 09:02:33
问题 I needed to find the sum of all pairs of numbers in a long list of pairs. Lots of ways to do this in Mathematica, but I was thinking of using either Plus or Total . Since Total works on lists, Map is the functional programming instrument to use there and Apply at level 1 (@@@) is the one to use for Plus , as Plus takes the numbers to be added as arguments. Here is some demo code ( warning : save all your work before executing this!): pairs = Tuples[Range[6000], {2}]; (* toy example *)

How to choose the numbers shown on the axes of a plot in mathemetica?

女生的网名这么多〃 提交于 2019-11-29 08:04:55
I have already checked all the examples and settings in the Mathematica documentation center, but couldn't find any example on how to choose the numbers that will be shown on the axes. How do I change plot axis numbering like 2,4,6,.. to PI,2PI,3PI,...? You can find an example here : Ticks -> {{Pi, 2 Pi, 3 Pi}, {-1, 0, 1}} Howard has already given the correct answer in the case where you want the labels Pi , 2 Pi etc to be at the values Pi , 2 Pi etc. Sometimes you might want to use substitute tick labels at particular values, without rescaling data. One of the other examples in the

Exporting Mathematica Print[] Output to a .txt file

白昼怎懂夜的黑 提交于 2019-11-29 07:40:40
问题 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? 回答1: 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

Uncaught Throw generated by JLink or UseFrontEnd

*爱你&永不变心* 提交于 2019-11-29 07:33:58
This example routine generates two Throw::nocatch warning messages in the kernel window. Can they be handled somehow? The example consists of this code in a file "test.m" created in C:\Temp: Needs["JLink`"]; $FrontEndLaunchCommand = "Mathematica.exe"; UseFrontEnd[NotebookWrite[CreateDocument[], "Testing"]]; Then these commands pasted and run at the Windows Command Prompt: PATH = C:\Program Files\Wolfram Research\Mathematica\8.0\;%PATH% start MathKernel -noprompt -initfile "C:\Temp\test.m" Addendum The reason for using UseFrontEnd as opposed to UsingFrontEnd is that an interactive front end may