wolfram-mathematica

Automatically generating sums in Mathematica

此生再无相见时 提交于 2019-12-06 06:05:58
This is a design issue I came across while working on implementation of Generalized Distributive Law . Suppose you need to automatically generate expressions of the following form (source: yaroslavvb.com ) Terms inside the sum, fixed variables and "summed over" variables are automatically generated for each such expression, and "f" functions are defined separately. To generate expression above, I may need to call sumProduct(factors,fixedVariables,fixedValues,freeVariables,freeRanges) where factors={{1,4},{3,4},{3,4,5}} fixedVariables={1,3} fixedValues={-1,9} freeVariables={4,5} freeRanges=

Mathematica: set default value for argument to nonconstant?

这一生的挚爱 提交于 2019-12-06 06:03:25
问题 Can I set the default value for a function argument to be something that's not constant? Example: tod := Mod[AbsoluteTime[], 86400] f[x_:tod] := x In the above, 'tod' changes every time I evaluate it, but "f[]" does not. "?f" yields: f[x_:42054.435657`11.376386798562935] := x showing the default value was hardcoded when I created the function. Is there a workaround here? 回答1: It seems to work if the function holds its arguments: tod := Mod[AbsoluteTime[], 86400] SetAttributes[f, HoldAll]; f[x

Difference in eigenvector transformations: Mathematica vs. SciPy

帅比萌擦擦* 提交于 2019-12-06 05:53:20
Similar questions have been asked previously here but none seem to answer my example. I compute the eigenvalues and eigenvectors of a matrix A using Mathematica and SciPy; the eigenvalues agree but this is not the case for the eigenvectors: (1) the lowest (eigenvalued) eigenvector agrees (2) the remaining corresponding eigenvectors of Mathematica and SciPy are not related by a multiplicative factor (3) I can compute the transformation matrix T sending SciPy's eigenvector to Mathematica's corresponding eigenvector using the outer product T = numpy.outer(MathematicaEigenvector, SciPyEigenvector)

TransformedDistribution in Mathematica

纵然是瞬间 提交于 2019-12-06 05:51:45
问题 I have developed some code to generate random variates from the product of a LogNormalDistribution and a StableDistribution: LNStableRV[{\[Alpha]_, \[Beta]_, \[Gamma]_, \[Sigma]_, \[Delta]_}, n_] := Module[{LNRV, SDRV, LNSRV}, LNRV = RandomVariate[LogNormalDistribution[Log[\[Gamma]], \[Sigma]], n]; SDRV = RandomVariate[ StableDistribution[\[Alpha], \[Beta], \[Gamma], \[Sigma]], n]; LNRV * SDRV + \[Delta] ] (* Note the delta serves as a location parameter *) I think this works fine: LNStableRV

What is causing this strange Mathematica result?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 05:51:37
问题 I've run into what seems like a bug in Mathematica 8. I can't find anything related to it online, but I admit I'm not exactly sure what to search for. If I run this statement: 0.05 + .10 /. {0.15 -> "pass"} 1.04 + .10 /. {1.14 -> "pass"} 1.05 + .10 /. {1.15 -> "pass"} 1.15 /. {1.15 -> "pass"} I get this output: pass pass 1.15 pass Am I just overlooking something? Edit: After reading the helpful discussion below, I changed my dispatch table to use a Which statement instead: f[x_] := Which[x ==

Convert Lat/Long to X/Y for Albers Projection on US Map Image

拜拜、爱过 提交于 2019-12-06 05:48:37
问题 I'm trying to use C# or Javascript to convert Lat/Longs into X/Y Coordinates to position divs with CSS (left, top) onto a background image of a US map. The standard map projection of the United States is an Albers Projection as seen below, but StackOverflow only has references for Lat/Long conversions that refer to basic Mercator projections. Map: http://en.wikipedia.org/wiki/File:Usa_counties_large.svg Map Size: 1460px width x 914px height Lat/Long Samples: LA: 34.0525, -118.2544 NY: 40.7582

How to Convert an Alphanumeric (Reference) Number Containing a Decimal Point to a String in Mathematica

走远了吗. 提交于 2019-12-06 05:34:26
问题 I have a reference number of the following type DAA76647.1 which I want to convert unchanged to a string in Mathematica. That is myfn[DAA76647.1] gives as output "DAA76647.1" Is there an easy way to do this? (The input cannot be a string and, other than conversion to a string, I do not want to change the input in any other way). Update ToString /@ {A1234, 1234.1, A1234 .5} gives the following output (where I have simply entered everything from the keyboard) {"A1234", "1234.1", "0.5 A1234"} It

Changing values in nested lists according to elements in the list

风流意气都作罢 提交于 2019-12-06 05:09:06
I have a list of pairs of values in mathematica, for example List= {{3,1},{5,4}} . How do I change the first element (3 & 5) if the second element does not reach a threshold. For example, if the second parts are below 2 then i wish the first parts to go to zero. so that list then = {{0,1},{5,4}} . Some of these lists are extremely long so manually doing it is not an option, unfortunately. Conceptually, the general way is to use Map . In your case, the code would be In[13]:= lst = {{3, 1}, {5, 4}} Out[13]= {{3, 1}, {5, 4}} In[14]:= thr = 2 Out[14]= 2 In[15]:= Map[{If[#[[2]] < thr, 0, #[[1]]], #

Optimizing a “Manipulate” in Mathematica

与世无争的帅哥 提交于 2019-12-06 03:58:16
I am looking to make a nice demo of the problem I mentioned in Integration in Mathematica but it is very slow yet and the Manipulate is not smooth at all. Considering the below, is there means by which I could improve the situation. That is see a more continuous dynamic. Also I can't get to have the Manipulator open using Control->Manipulator[Appearance->Open] arrows = ParallelTable[{ RandomVariate[NormalDistribution[0, Sqrt[1]]], RandomVariate[NormalDistribution[0, Sqrt[1]]]}, {20000}]; Manipulate[ Graphics[{ White, Rectangle[{-5, -5}, {5, 5}], Red, Disk[{0, 0}, 1], Black, Point /@ (arrows[[;

Mathematica internal number formats and precision

主宰稳场 提交于 2019-12-06 03:33:40
问题 Tangentially related to this question, what exactly is happening here with the number formatting? In[1] := InputForm @ 3.12987*10^-270 Out[1] := 3.12987`*^-270 In[2] := InputForm @ 3.12987*10^-271 Out[2] := 3.1298700000000003`*^-271 If you use *10.^ as the multiplier the transition is where you would naively expect it to be: In[3] := InputForm @ 3.12987*10.^-16 Out[3] := 3.12987`*^-16 In[4] := InputForm @ 3.12987*10.^-17 Out[4] := 3.1298700000000004`*^-17 whereas *^ takes the transition a bit