wolfram-mathematica

Using Mathematica Gather/Collect properly

家住魔仙堡 提交于 2019-12-22 06:23:12
问题 How do I use Mathematica's Gather/Collect/Transpose functions to convert: { { {1, foo1}, {2, foo2}, {3, foo3} }, { {1, bar1}, {2, bar2}, {3, bar3} } } to { {1, foo1, bar1}, {2, foo2, bar2}, {3, foo3, bar3} } EDIT: Thanks! I was hoping there was a simple way, but I guess not! 回答1: Here is your list: tst = {{{1, foo1}, {2, foo2}, {3, foo3}}, {{1, bar1}, {2, bar2}, {3, bar3}}} Here is one way: In[84]:= Flatten/@Transpose[{#[[All,1,1]],#[[All,All,2]]}]&@ GatherBy[Flatten[tst,1],First] Out[84]= {

Mathematica calls NMinimize with symbols rather than numbers?

落花浮王杯 提交于 2019-12-22 05:06:41
问题 I noticed the following behavior while using NMinimize in Mathematica. The first invocation of the objective function is with variable names, rather than with points from the space, as one would expect. So for example if my objective function is a module, this module is called only once, evaluated symbolically and then in further iterations, this symbolic expression is evaluated with points from the variable space. This behavior could slow down the computation significantly for a large

Understanding Kernel-FrontEnd communication — Why does my Front End freeze?

霸气de小男生 提交于 2019-12-22 04:46:17
问题 EDIT: Just a confirmation whether you can reproduce this or not would be useful. Only a single computer is needed to try this (no remote connection necessary). Update It seems other can't reproduce this on Mac or Win7, so it's either WinXP-specific or specific to my machine. At this point I'm giving up. It would be good to have a tutorial on how the Front End and the Kernel communicate, so we can debug remote kernel issues. Any such general answers (or links to tutorials elsewhere) are most

Automatically saving notebook (or other type files in mathematica) files

↘锁芯ラ 提交于 2019-12-22 04:41:01
问题 I have been facing this problem for sometimes now, a laziness caused in part by the fact that Microsoft Office automatically save files you are working on with versions and automatic recovery. Many times when I am starting a new notebook in mathematica to do some tests or whatever, I often forget to save what I am doing. Every now and then, depending on the computer I am using, the computer crashes and all the beautiful work I was doing is lost forever... Is there a way to get around this

Is it possible to delete “context`” from the list of loaded Contexts[]?

独自空忆成欢 提交于 2019-12-22 04:17:18
问题 We can remove all symbols in a particular context by using Remove["context`*"] . But is it possible to remove "context`" itself from the system so that it will no longer be listed in Contexts[]? 回答1: As far as I can tell (a guess), a context is automatically removed from Contexts[] once it becomes empty (has no symbols). At least, this happens in my tests. Here is one: In[1]:= BeginPackage["Test`"] EndPackage[] Out[1]= Test` In[3]:= MemberQ[Contexts[],"Test`"] Out[3]= False In[4]:= Test`a Out

Concatenate two integers in Mathematica 7

女生的网名这么多〃 提交于 2019-12-22 04:00:50
问题 What is the most efficient way to concatenate two positive integers in Mathematica 7? cc[123, 4567] >> 1234567 What about more than two? cc[123, 4, 567, 89] >> 123456789 回答1: This will be slightly faster for many integers, than your last solution: ToExpression[StringJoin @@ Map[IntegerString, {##}]] & A more concise alternative is to accept a single argument, assuming it to be a list, rather than a sequence, of numbers to concatenate: ToExpression@StringJoin@IntegerString@#& which is based on

Add text to faces of polyhedron

和自甴很熟 提交于 2019-12-22 03:20:47
问题 Is it possible to automate the addition of any text to the faces of a polyhedron, like this manually-drawn graphic shows (the example's odd numbering scheme isn't relevant): It was easy enough to label the vertices: c = 1; Show[{Graphics3D[ Text[c++, #] & /@ PolyhedronData["Dodecahedron", "VertexCoordinates"]], PolyhedronData["Dodecahedron"]}, Boxed -> False] (even though some of the text is placed in front of the shape for vertices that are hidden. That's probably soluble.) But when I tried

Putting a VerticalSlider into Mathematica's Manipulate?

跟風遠走 提交于 2019-12-21 23:37:28
问题 How do you set up manipulate so that you can control a variable with a vertical slider instead of a horizontal slider in Mathematica? 回答1: From the help .... Manipulate[u, {u, 0, 1, ImageSize -> Small}, ControlType -> VerticalSlider, ControlPlacement -> Left] 来源: https://stackoverflow.com/questions/4418699/putting-a-verticalslider-into-mathematicas-manipulate

Vertical alignment of plots in mathematica via GraphicsColumn

回眸只為那壹抹淺笑 提交于 2019-12-21 21:12:05
问题 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

NMinimize eats all memory b/c of unnecessary symbolic work

梦想的初衷 提交于 2019-12-21 20:52:06
问题 The following code is a naive way to find the least number whose square has n divisors (the minimum should be its log and the x_i the powers in its prime factorization). If I look at the case n=2000 and use ten variables instead of twenty, this uses somewhere around 600MB of memory. With the value of n I'm actually trying to find the answer for, I need around 20 variables to be sure of not missing the actual solution, and it quickly uses up all available memory and then thrashes swap. n=8*10