Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is recipe from Stan Wagon's book...use it when built-in Plot behaves erratically due to lack of precision</p> <pre><code>Options[PrecisePlot] = {PrecisionGoal -&gt; 6}; PrecisePlot[f_, {x_, a_, b_}, opts___] := Module[{g, pg}, pg = PrecisionGoal /. {opts} /. Options[PrecisePlot]; SetAttributes[g, NumericFunction]; g[z_?InexactNumberQ] := Evaluate[f /. x -&gt; z]; Plot[N[g[SetPrecision[y, \[Infinity]]], pg], {y, a, b}, Evaluate[Sequence @@ FilterRules[{opts}, Options[Plot]]]]]; </code></pre> <p>I often use the following trick from Kristjan Kannike's when I need "dictionary-like" behavior from Mathematica's downvalues</p> <pre><code>index[downvalue_, dict_] := (downvalue[[1]] /. HoldPattern[dict[x_]] -&gt; x) // ReleaseHold; value[downvalue_] := downvalue[[-1]]; indices[dict_] := Map[#[[1]] /. {HoldPattern[dict[x_]] -&gt; x} &amp;, DownValues[dict]] // ReleaseHold; values[dict_] := Map[#[[-1]] &amp;, DownValues[dict]]; items[dict_] := Map[{index[#, dict], value[#]} &amp;, DownValues[dict]]; indexQ[dict_, index_] := If[MatchQ[dict[index], HoldPattern[dict[index]]], False, True]; (* Usage example: *) (* Count number of times each subexpression occurs in an expression *) expr = Cos[x + Cos[Cos[x] + Sin[x]]] + Cos[Cos[x] + Sin[x]] Map[(counts[#] = If[indexQ[counts, #], counts[#] + 1, 1]; #) &amp;, expr, Infinity]; items[counts] </code></pre> <p>When evaluation results are confusing, sometimes it helps to dump evaluation steps into a text file</p> <pre><code>SetAttributes[recordSteps, HoldAll]; recordSteps[expr_] := Block[{$Output = List@OpenWrite["~/temp/msgStream.m"]}, TracePrint[Unevaluated[expr], _?(FreeQ[#, Off] &amp;), TraceInternal -&gt; True]; Close /@ $Output; Thread[Union@ Cases[ReadList["~/temp/msgStream.m", HoldComplete[Expression]], symb_Symbol /; AtomQ@Unevaluated@symb &amp;&amp; Context@Unevaluated@symb === "System`" :&gt; HoldComplete@symb, {0, Infinity}, Heads -&gt; True], HoldComplete] ] (* Usage example: *) (* puts steps of evaluation of 1+2+Sin[5]) into ~/temp/msgStream.m *) recordSteps[1+2+Sin[5]] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload