Tag Info

Hot answers tagged

6

Define L = (1/2) (D[#, x] + D[#, y]) & We see that L works as desired. For instance: Simplify[Nest[L, f[x, y], 3]] (* (Derivative[0, 3][f][x, y] + 3*Derivative[1, 2][f][x, y] + 3*Derivative[2, 1][f][x, y] + Derivative[3, 0][f][x, y])/8 *) And the Sum can be constructed in a similar manner. For instance: Simplify[Sum[Nest[L, f[x, y], n], {n, ...


5

When you enter a number with a decimal point like: x = 8.168643234; you are telling Mathematica that this is a machine precision number. You can see this with: Precision[x] (* MachinePrecision *) This means that the internal representation of the number is not exactly what you entered, but instead is the nearest machine real. RealDigits shows you the ...


4

Here is a function makeOperator that takes any polynomial together with a replacement rule that maps the desired variable onto the desired operator. It outputs the result as a new operator: Clear[makeOperator]; makeOperator[poly_, Rule[x_, op_]] /; PolynomialQ[poly, x] := Module[{f}, Function[#1, #2] & @@ {f, Expand[poly]} /. Power[x, n_: 1] ...


3

The obvious way to modify your code is Clear[f, r] r[x_, n_] := If[x > 0, Print[n]; x*r[x - 1, n + 1], 1] f[k_Integer /; k > 1] := r[k, 1] For small values of x, this works fine. f[5] But it is very inefficient and also limited by $RecursionLimit. Block[{$RecursionLimit = 20}, f[24]] Both these issues can be addressed by using a less ...


3

There is a nice function BenchmarkPlot The usage is something like this Needs["GeneralUtilities`"] BenchmarkPlot[{f1,f2}, # &, PowerRange[1, 1000], "IncludeFits" -> True] Typical output: There are already many examples on MMA.SE.


2

There is some built-in binary search code but not in the core language as far as I know. There is BinarySearch from the Combinatorica package, which is still the function I use most often despite the fact that that package is now deprecated and loading it causes shadowing of some Symbols. There is the undocumented GeometricFunctions`BinarySearch but this ...


1

I really don't get it. But here's walk-around. It seems that within projected area is everything with longitude in interval: {t-180, t+180} and if you set t = -180 algorithm does not care that it is plotting {-360 , 0} while oryginal data has domain {-180, 180}. We have to take care wbout Mod ourselvs: pos = Cases[ CountryData["World", ...


1

Please tell me if this simplified function does what you want: f[x_, n_] := Round[x, 10^(1 - n + ⌊ Log10 @ Abs @ x ⌋)] ~SetPrecision~ n Test: Table[f[x*Pi, 4], {x, {1/100, 1/10, 1, 10, 100}}] % // FullForm {0.03142, 0.3142, 3.142, 31.42, 314.2} List[0.03142`4., 0.3142`4., 3.142`4., 31.42`4., 314.2`4.] Related Q&A's: Meaning of backtick in ...


1

Most users probably want to use SetPrecision, which preserves extra digits and automagically handles fractional digits of precision. However, in this case, we need to somehow override this behavior. I'll use a custom object, sigFigNumber. First I'll define how it's displayed. Format[sigFigNumber[s_, d_]] := N[s, d] So we can see that sigFigNumber has ...


1

Internally LineScaledCoordinate use Position[d, _?(#1 >= t &)] to detect a current segment. Here d is an accumulated list of distances (relative to the total length of segments). However, algebraic expressions are not atomic: t = 0.5; d = {0, 1/(3 + Sqrt[2]), 3/(3 + Sqrt[2]), 1}; Position[d, _?(#1 >= t &)] Position[N@d, _?(#1 >= t ...



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