wolfram-mathematica

The semantics of Mathematica's Thread function, someone needs to finally put this to rest

时光毁灭记忆、已成空白 提交于 2019-12-09 08:20:54
问题 Wolfram Research has had the same documentation for this function for the last 8 years at least: Thread[f[args]] "threads" f over any lists that appear in args. A lovely circular definition if I've ever seen one. Does anyone know what the actual semantics are and can provide a proper explanation that is non-circular? 回答1: Thread is a bit like a generalization zip from other functional languages. For simple cases, where all the elements of args from your example are lists, Thread[f[args]] is

Getting the Mathematica front end to obey the FontFamily option

杀马特。学长 韩版系。学妹 提交于 2019-12-09 08:01:02
问题 When it comes to Chinese characters, I am unable to get the Front End of Mathematica to use the fonts of my choice. How can I get it to use the fonts I need? Here I provide two screenshots to show the problem, one from Word (top), the other from Mathematica on WinXP, both displaying the same string. Note that Mathematica uses several different fonts (I guess it uses font substitution when the font it tries to use first doesn't contain a glyph---however the font I specified contains all glyphs

How do I store the results of a long symbolic calculation for later use?

我怕爱的太早我们不能终老 提交于 2019-12-09 07:18:00
问题 My calculations are something like this: f[x_]:= (*runs fast*) g[x_]:=(*runs fast*) h[x_]=depends on f[x],g[x] (*runs slow ~5mins*) Now I need only the results of h[x] and every time I restart mma, I essentially redo the same calculations to get h[x] , when it could have been stored. Is there some way I can save the symbolic results, and just import it anytime I need it? 回答1: Try Save Use like: Save["h-defs.m", h] And load with Get: << "h-defs.m" 来源: https://stackoverflow.com/questions

Design approach: Overloading vs Switch?

一笑奈何 提交于 2019-12-09 05:14:01
问题 In regard to performance and scalability in package design, is it best to: … ‘overload’ function names (letting Mathematica sort out which version to use based on patterns/conditions/tests and the way the system orders definitions)? … or to construct a single function with a Switch[] (or similar command) to direct evaluation? Mathematica’s expressiveness frequently confuses me with silly (?) issues like this. 回答1: This is a broad question, but I will take this opportunity to give a broad

Simplify Regular Expression in Mathematica

你。 提交于 2019-12-09 04:12:55
问题 I recently found out about Kleene algebra for manipulating and simplifying regular expressions. I'm wondering if this has been build into any computational software programs like Mathematica? It would be great to have a computational tool for doing unions and concatenations of large expressions and have the computer simplify them. If you are not aware of any programs with this algebra built in, do you know any programs that allow extending their engines with new algebras? 回答1: On http://www

Simple way to delete a matrix column in Mathematica

谁说我不能喝 提交于 2019-12-09 03:03:20
问题 I am trying to delete both a matrix in mathematica. An inelegant way of doing it is as I do below, i.e specifying it in a new matrix as S = Table[ Ss[[If[i < t, i, i + 1]]][[If[j < t, j, j + 1]]], {i, q}, {j, q}]; where the goal is to eliminate row and column t. Indeed delete a line is easy Delete[Ss,t]. For the column column I suppose I could do Transpose[Delete[Transpose[Ss,t]]] My primary concern is to do it in a way that executes the fastest way possible. More generally, is there a

Unsort: remembering a permutation and undoing it

独自空忆成欢 提交于 2019-12-09 00:45:34
问题 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

Why does FindMaximum with Newton's method complain it can't find a sufficient decrease in function?

痴心易碎 提交于 2019-12-08 21:00:31
Firstly, this seems like (from ContourPlot) a fairly straightforward maximization problem, why is FindMaximum with Newton's method having problems? Secondly, how can I get rid of the warnings? Thirdly, if I can't get rid of these warnings, how can I tell if the warning is meaningful, ie, maximization failed? For instance, in the code below, FindMaximum with Newton's method gives a warning, whereas the PrincipalAxis method doesn't o = 1/5 Log[E^(-(h/Sqrt[3]))/( 2 E^(-(h/Sqrt[3])) + 2 E^(h/Sqrt[3]) + E^(-(h/Sqrt[3]) - Sqrt[2] j) + E^(h/Sqrt[3] - Sqrt[2] j) + E^(-Sqrt[3] h + Sqrt[2] j) + E^(Sqrt

A programming challenge with Mathematica

随声附和 提交于 2019-12-08 20:59:27
I am interfacing an external program with Mathematica. I am creating an input file for the external program. Its about converting geometry data from a Mathematica generated graphics into a predefined format. Here is an example Geometry. Figure 1 The geometry can be described in many ways in Mathematica. One laborious way is the following. dat={{1.,-1.,0.},{0.,-1.,0.5},{0.,-1.,-0.5},{1.,-0.3333,0.},{0.,-0.3333,0.5}, {0.,-0.3333,-0.5},{1.,0.3333,0.},{0.,0.3333,0.5},{0.,0.3333,-0.5},{1.,1.,0.}, {0.,1.,0.5},{0.,1.,-0.5},{10.,-1.,0.},{10.,-0.3333,0.},{10.,0.3333,0.},{10.,1.,0.}}; Show

How to close initialization cell in Notebook?

你。 提交于 2019-12-08 19:23:17
问题 In my Notebook I have a fairly large initialization cell. How to make it close-able? I mean how can I roll up this cell in one line with ability to unroll it back? 回答1: The classic solution is to put the initialization cell(s) into a Section (Alt+4) of their own, titled "Initialization." This Section goes either at the start or end of your notebook. To hide the contents, you close the Section (double click its cell bracket at right of window). 回答2: I have found the solution. I should create a