wolfram-mathematica

Context unique to each group at a specified level

血红的双手。 提交于 2019-11-30 15:25:34
问题 Recent versions of Mathematica provide the option of having a unique $Context for each cell group, via: Evaluation > Notebook's Default Context > Unique to Each Cell Group This is an appealing concept, but I find it unusable, as my code spans multiple cell groups. I would like a way to specify a unique context for cell groups of a certain level such as every Section , but not a separate context for every Subsection or Subsubsection . A solution will need to affect new cell groups as they are

Paste Mathematica code so that's it's broken into separate input cells

扶醉桌前 提交于 2019-11-30 15:25:09
问题 I often copy Mathematica code from websites (such as SO) to a notebook. The code usually gets pasted as a single input cell. I'm looking for a simple way to paste it as several input cells for convenient step-by-step evaluation. For example, a = 2; f[x_] := x^a Plot[f[x], {x,0,2}] would ideally paste as two input cells. Manual formatting (i.e. the original newlines) should preferably also be preserved (this is not the case with default pasting). Generally, if one selects all input cells (ALT

Why do BarChart graphics exported from Mathematica have pixelated text? Is there a workaround?

孤街醉人 提交于 2019-11-30 15:23:10
I've been showing off my fancy new graph formats to colleagues, but we have discovered that graphics based on BarChart have jagged text when exported as EMF, WMF, PDF etc. Line graphs based on ListLinePlot , DateListPlot etc do not have this problem. Short of Rasterize -ing every Export function automatically (it's for an application for end-users so they can't be expected to fiddle with it themselves), is there a workaround? It's a surprise because the documentation says: Since EMF supports vector graphics, fonts are not rasterized when exporting to EMF. EDIT If it's relevant, font used is

Memoization in OCaml?

风格不统一 提交于 2019-11-30 15:22:50
It is possible to improve "raw" Fibonacci recursive procedure Fib[n_] := If[n < 2, n, Fib[n - 1] + Fib[n - 2]] with Fib[n_] := Fib[n] = If[n < 2, n, Fib[n - 1] + Fib[n - 2]] in Wolfram Mathematica. First version will suffer from exponential explosion while second one will not since Mathematica will see repeating function calls in expression and memoize (reuse) them. Is it possible to do the same in OCaml? How to improve let rec fib n = if n<2 then n else fib (n-1) + fib (n-2);; in the same manner? You pretty much do what the mathematica version does but manually: let rec fib = let cache =

Setting up a “struct” in Mathematica safely

自古美人都是妖i 提交于 2019-11-30 15:05:46
The question on making a record like in Mathematica has been discussed in few places, such as Struct data type in Mathematica? . The problem with all these methods, is that one loses the ability, it seems, to do the specific extra check on each argument, as in when one does x_?NumericQ . My question is: Is there a way in Mathematica to make a record or a struct, and yet be able to use the checking as above on the individual elements? I am trying to settle down on one method to use as I am tired of having functions called with 10 parameters on them (sometimes one can't avoid this), even when I

Test if an expression is a Function?

喜夏-厌秋 提交于 2019-11-30 14:53:33
How would a function FunctionQ look like, maybe in a way I can even specify the number of arguments allowed? I really feel bad posting after Simon and Daniel, but their codes fail on non-functions which are not symbols. Checking for that and adding a check for builtins via NumericFunction , as suggested by Simon, we arrive at something like FunctionQ[_Function | _InterpolatingFunction | _CompiledFunction] = True; FunctionQ[f_Symbol] := Or[ DownValues[f] =!= {}, MemberQ[ Attributes[f], NumericFunction ]] FunctionQ[_] = False; which should work in some (sigh) real-world cases In[17]:= FunctionQ/

Inverse of Flatten in Mathematica?

最后都变了- 提交于 2019-11-30 14:38:56
What's the inverse of f[x_]:=Flatten[x] where x is Array with dimensions dims? Michael Pilat There is no built-in function, but it's pretty easy with a combination of Fold and Partition : In[47]:= x1 = RandomReal[{0, 1}, {3, 4, 5}]; In[48]:= dims = Dimensions[x1] Out[48]= {3, 4, 5} In[49]:= x2 = Fold[Partition, Flatten[x1], Most[Reverse[dims]]]; In[50]:= x1 == x2 Out[50]= True High Performance Mark You probably want Partition[] or one of its relatives. 来源: https://stackoverflow.com/questions/3807976/inverse-of-flatten-in-mathematica

Context unique to each group at a specified level

戏子无情 提交于 2019-11-30 14:33:00
Recent versions of Mathematica provide the option of having a unique $Context for each cell group, via: Evaluation > Notebook's Default Context > Unique to Each Cell Group This is an appealing concept, but I find it unusable, as my code spans multiple cell groups. I would like a way to specify a unique context for cell groups of a certain level such as every Section , but not a separate context for every Subsection or Subsubsection . A solution will need to affect new cell groups as they are created. You should be able to do this by modifying your notebook's stylesheet. You can use the option

How do you get custom 3D graphics to display properly in Mathematica?

廉价感情. 提交于 2019-11-30 14:30:56
I need to incorporate a 3D model of the Earth into a satellite orbit intercept simulation I have created in Mathematica (I need it to work with "Graphics3D[]). I have downloaded several different models in formats that Mathematica claims to support and I even created my own in Pro/E. The ones that actually do get imported into the program (using "Import[]") lose their surface image and I am left with a generic sphere. How can I get custom 3D graphics to import correctly into Mathematica? Are certain formats better than others? (I have been using mostly CAD models) And is there place to

Aggregating Tally counters

风格不统一 提交于 2019-11-30 14:04:36
Many times I find myself counting occurrences with Tally[ ] and then, once I discarded the original list, having to add (and join) to that counters list the results from another list. This typically happens when I am counting configurations, occurrences, doing some discrete statistics, etc. So I defined a very simple but handy function for Tally aggregation: aggTally[listUnTallied__List:{}, listUnTallied1_List, listTallied_List] := Join[Tally@Join[listUnTallied, listUnTallied1], listTallied] //. {a___, {x_, p_}, b___, {x_, q_}, c___} -> {a, {x, p + q}, b, c}; Such that l = {x, y, z}; lt =