wolfram-mathematica

(MathLink) Correct handling of Messages generated by slave kernel

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 00:03:29
When working through MathLink with slave kernel I have a problem with correct parsing TextPacket s. In particular when such packet corresponds to a Message generated by the slave kernel I do not understand how to handle it correctly at all. I need such Messages to be printed in the evaluation notebook as if they were generated by master kernel (but with some mark to make clear that it comes from the slave). And I need to separate TextPacket s corresponding to Message s from just to Print[] commands. The latter I need to parse correctly too, printing them in the evaluation notebook with a

How to create 2D (3D) animation in Wolfram Mathematica with the camera following the object?

独自空忆成欢 提交于 2019-11-30 23:26:36
I have a graphical object which is moving along a trajectory. How can I make the camera follow the object? Since the question asks about 2D, here's how you can emulate a camera in 2D Graphics. First, let's get the stackoverflow favicon.ico: so = First@Import["http://sstatic.net/stackoverflow/img/favicon.ico"] Well put this on top of some overlapping circles and make the "camera" follow the icon around by adjusting the PlotRange Manipulate[Graphics[{ Table[Circle[{j, 0}, i], {i, 0, 1, .1}, {j, {-.5, .5}}], Inset[so, pos, {0, 0}, .2]}, PlotRange -> {{-.5, .5}, {-.5, .5}} + pos], {{pos, {0, 0}, "

Plotting linear inequalities in Mathematica

孤街浪徒 提交于 2019-11-30 22:35:46
I have linear systems of inequalities in 3 variables and I'd like to plot these regions. Ideally, I'd like something that looks like objects in PolyhedronData. I tried RegionPlot3D, but the results are visually poor and too polygon-heavy to rotate in real time Here's what I mean, the code below generates 10 sets of linear constraints and plots them randomCons := Module[{}, hadamard = KroneckerProduct @@ Table[{{1, 1}, {1, -1}}, {3}]; invHad = Inverse[hadamard]; vs = Range[8]; m = mm /@ vs; sectionAnchors = Subsets[vs, {1, 7}]; randomSection := Mean[hadamard[[#]] & /@ #] & /@ Prepend

How to Autonumber Cell Tags in Mathematica Notebooks?

大城市里の小女人 提交于 2019-11-30 22:02:34
I tried to follow the directions on autonumbering cells in a Mathematica-8 notebook, here http://reference.wolfram.com/mathematica/tutorial/AutomaticNumbering.html I created a tiny notebook with four text cells foo qux blancmange bar Placing the cursor just before foo , I then used the Insert menu, Automatic numbering item, giving me the Create Automatic Numbering Object dialog box. I chose in the Counter dropdown then item Text , clicked This counter object radio button, and Huzzah! got the number 1 just before foo , presumably referring to the first cell of type Text in the notebook. I now

Finding frequency of range of numbers in Mathematica

回眸只為那壹抹淺笑 提交于 2019-11-30 21:29:47
Given a list of numbers in Mathematica, how would I extract from that list the total number of numbers between numbers a and b that I specify? The most direct way is simply: Count[data, x_ /; a <= x <= b] There are however much faster ways for most data, this one thanks to Carl Woll: Tr@Unitize@Clip[data, {a, b}, {0, 0}] Carl Woll's method is particularly fast, but as yoda pointed out, it fails if your list contains zeros, and your range also straddles zero. Here is another method from Kevin J. McCann that handles this case, and is still very fast: Tr@UnitStep[(data - a)*(b - data)] As a pure

Unsort: remembering a permutation and undoing it

笑着哭i 提交于 2019-11-30 21:24:43
Suppose I have a function f that takes a vector v and returns a new vector with the elements transformed in some way. It does that by calling function g that assumes the vector is sorted. So I want f to be defined like so: f[v_] := Module[{s, r}, s = Sort[v]; (* remember the permutation applied in order to sort v *) r = g[s]; Unsort[r] (* apply the inverse of that permutation *) ] What's the best way to do the "Unsort"? Or could we get really fancy and have this somehow work: answer = Unsort[g[Sort[v]]]; ADDED: Let's make this concrete with a toy example. Suppose we want a function f that

How is the BarSpacing option really implemented in Mathematica?

笑着哭i 提交于 2019-11-30 20:41:24
I'm trying to implement a DateListBarChart function that takes dated data and outputs a bar chart with the same placements as DateListPlot . It's essential that they plot data in the same horizontal position if given the same data, so they can be combined using Show . I am finding it difficult to get the settings for BarSpacing right so that the horizontal range of the plot doesn't change, and the bars stay in essentially the same place. I have been unable to infer the correct scaling so that BarSpacing->{0.2,0.3} results in 20% of the x-axis length available for that group of bars is taken up

Convenient way to add inline formatting to usage Messages

与世无争的帅哥 提交于 2019-11-30 20:40: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\"]], \":>\", SubscriptBox[StyleBox[\"act\", \"TI\"], \ StyleBox[\"2\", \"TR\"]]}], \",\", StyleBox[\"\[Ellipsis]\", \

Can the frame border on a BarChart Legend be removed?

吃可爱长大的小学妹 提交于 2019-11-30 20:14:32
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, 4.475, \ 3.857, 3.215, 2.206, 2.206, 2.117, 3.403, 3.277, 3.761, 4.276, 2.559, \ 3.486, 4.778, 2.281,

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

狂风中的少年 提交于 2019-11-30 20:06:07
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 prime numbers to a more realistically, but still very moderate size. n = 252097800611*252097800629 In