Hot answers tagged

4

When you evaluate the statement opt=="def" it evaluates to True if opt really is "def", but it doesn't give False for any other object. Read the answer here to see why you need to use SameQ (===) instead of Equal (==), f[a_, opt_] := Module[{defOpt, opt2}, defOpt = {PlotLabel -> "Label"}; If[opt === "def", opt2 = defOpt, opt2 = Join[defOpt, opt]]; ...


3

To define a function with options, give it a set of defaults and use OptionsPattern in the definition. To use the value of a particular option in the function defintion, use OptionValue: Options[f] = {"ThisIsAnOption" -> False, SoIsThis -> 1}; f[a_, opt : OptionsPattern[]] := (If[OptionValue["ThisIsAnOption"], Print[{opt}]]; a + ...


3

A compact approach is ParametricPlot[ReIm[Log[θ] Exp[I θ]], {θ, 0, 2 Pi}] producing the same curve that appears in the answer by thedude. It works for any complex function of a single real variable. Appropriate to the season, a cartiod can be plotted by ParametricPlot[ReIm[I(Exp[I θ] + 1)^2], {θ, -Pi, Pi}]


2

You want to look at RepeatedTiming Table[{n, First@RepeatedTiming[RandomPrime[{10^n, 100^(n + 1)}]]}, {n, 100, 1500, 100}] (*{{100, 0.02}, {200, 0.1}, {300, 0.5}, {400, 0.9}, {500, 0.7}, {600, 5.}, {700, 1.*10^1}, {800, 1.*10^1}, {900, 3.*10^1}, {1000, 5.*10^1}, {1100, 51.}, {1200, 3.*10^1}, {1300, 7.*10^1}, {1400, 1.*10^2}, {1500, 1.*10^2}} ...


1

Upon MarcoB's suggestion: complex[θ_] = Exp[I θ]; ListPlot[Table[ReIm@complex@θ, {θ, 0, 2 Pi, 0.01}], AspectRatio -> Automatic, Joined -> True] Example complex[θ_] = Log@θ Exp[I θ]; ListPlot[Table[ReIm@complex@θ, {θ, 0, 2 Pi, 0.01}], AspectRatio -> Automatic, Joined -> True]


1

A plot of DiracDelta is at best an approximation to the behavior of the underlying mathematical construct. This has been discussed before on this site; see for instance Calling Correct Function for Plotting DiracDelta and the answers within. In your case, you could perhaps try the following: ListLinePlot[ Table[{x, Piecewise[{{1, x == -3}, {0, True}}, ...



Only top voted, non community-wiki answers of a minimum length are eligible