Tag Info

New answers tagged

1

Having upgraded to Mathematica 10.0.0, it turns out that the Distribution library greatly facilitates the numerical simulation of boson-sampling experiments using the above PermanentCode` package. The built-in function KolgomorovSmirnovTest is particularly valuable; the Wikipedia entry Kolmogorov–Smirnov test provides a good introduction. The appended ...


3

As far as I understand the concept there is no true pass-by-reference in Mathematica. Attempting to make assignments to arguments is in fact a common mistake which I addressed in this answer: Attempting to make an assignment to the argument of a function. As described there one needs a Hold attribute for in-place modification of definitions, e.g.: ...


5

How about using "RuntimeErrorHandler": f = Compile[{{x, _Real}, {y, _Real}}, Log[(x - y^2 - 2. x)^2]/(y x^2 - 2 (x + y) - y^2 + 3.), "RuntimeOptions" -> {"RuntimeErrorHandler" -> Function[Throw[$Failed]]} ]; Catch[Quiet@f[-196, 15]] // AbsoluteTiming (* {0.000019, 0.0000116843} *) Catch[Quiet@f[-196, 14]] // AbsoluteTiming (* {0.000051, ...


4

I use \$MessagePrePrint = StandardForm since without that the real number 1.5 is displayed in a message as 1.5`. However, you might have $MessagePrePrint set to something else. Check is used to control what should happen when a built-in message occurs. Quiet prevents the built-in message from being displayed. I made a pure function (i.e. #1,#2,& ...


3

If you use an intermediate function as demonstrated in this answer, you'll get rid of all error messages that are related to the symbolic evaluation: derivativeStrategyLongStraddleCompiled2[currentPrice_?NumberQ, strikePrice_?NumberQ, callPremium_?NumberQ, putPremium_?NumberQ] := derivativeStrategyLongStraddleCompiled[currentPrice, strikePrice, ...


4

No, Mathematica does not include a C compiler. So if you want to learn C you will need to install a C compiler.


1

Span can be compiled: << CompiledFunctionTools` cf = Compile[{{lst, _Real, 1}}, lst[[;; 2]]]; CompilePrint@cf Pictured by Simon Wood's shadow. All used as an argument of Part can be compiled: cf2 = Compile[{{lst, _Real, 2}}, lst[[All, ;; 2]]]; CompilePrint@cf2 while All used as an argument of Span, which is the FullForm of (* a number* ) ...


2

The following are compilable in M10 but aren't in previous versions: {Indexed, LogisticSigmoid}


11

Okay, this is a bit of an embarassment. Here is a very small modification of the original code. I simply made explicit option settings, made a denominator to Sin explicitly real, that kind of thing. My tests show the same timing as the original, give or take an iota. ie = 200; ez = ConstantArray[0., {ie + 1}]; hy = ConstantArray[0., {ie}]; fdtd1d = ...



Top 50 recent answers are included