# Tag Info

## Hot answers tagged functions

9

You are asking for a solution to the equation $10^r\equiv 1$, mod $n$, where in your particular case $n=37$. The multiplicative order is the smallest exponent $r$ such that $x^r\equiv 1$, mod $n$. The multiplicative order is given by the Mathematica command MultiplicativeOrder[x,n], and corresponds to the "Foo" you asked for in your comment to @mgamer. ...

8

If your operation can be converted to a canonical ranking rather than a pairwise comparison then you can use MaximalBy introduced in version 10. If not a good approach to a single pass through a list is Fold. Here is a function using that: foldMax[list_, p_] := Fold[If[p[##], ##] &, list] This proves to be faster in some cases than using Ordering ...

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 ...

5

Another way of doing it (something similar to Kuba's great answer) is: Sum[HoldForm[#1 - #2] &[1/(2 i - 1), 1/(2 i + 1)], {i, 1, 6}] May be also something different: Sum[(1/(2 i - 1) - 1/(2 i + 1) // Trace)[[-2]], {i, 1, 6}]

5

HoldForm[# - #2] & @@@ Table[{1/(2 i - 1), 1/(2 i + 1)}, {i, 1, 6}] // Total

5

FullForm is a formatting wrapper(1)(2)(3). It does not change the way that the expression it contains evaluates but rather the way it is displayed by the Front End. You can combine it with HoldForm, which is another formatting wrapper that specifically holds its argument, to show the unevaluated full form of an expression: Cases[{a^2, a^3}, a_^1] // ...

5

As already mentioned in the comment: FullForm is a function that evaluates in the standard way because it has no attribute saying otherwise. One consequence is that before FullForm acts on your input, it evaluates it, which leave only the result of cases. None of this helps you to get your answer anyway. One easy way is to use Unevaluated on arguments to ...

5

I can reproduce this problem only if the Suggestions Bar is enabled. In this case DeleteMissing seems to mysteriously lose its definition. In[1]:= {$Version,$VersionNumber, $ReleaseNumber} Out[1]= {"10.0 for Mac OS X x86 (64-bit) (December 4, 2014)", 10., 2} In[2]:= a = {Missing[], 1, 2, 3} Out[2]= {Missing[], 1, 2, 3} In[3]:= DeleteMissing[a] Out[3]= ... 4 IntegerQ is meant for programming and tests for a data type, not whether something is mathematically an integer. Element is meant to represent a mathematical concept. The two are not interchangeable. Functions ending in ...Q always return True or False. Since the data type of x is not Integer (in the programming sense---it's a symbol), IntegerQ[x] ... 4 One more subtle variation: Sum[Defer[# - #2] & @@ (1/(2 i + {-1, 1})), {i, 6}] (1/11 - 1/13) + (1/9 - 1/11) + (1/7 - 1/9) + (1/5 - 1/7) + (1/3 - 1/5) + (1 - 1/3) 4 You need to understand how to define a function and how replacement rules work. This is a nice start point. f[c_, d_, z_] := c + d z s = Solve[{f[c, d, 1] == 2, f[c, d, -1] == 1}, {c, d}] (* {{c -> 3/2, d -> 1/2}} *) Print["c=", c /. s[[1]], " d=", d /. s[[1]]] (* c=3/2 d=1/2 *) 4 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 ...

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] ...

4

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", ...

4

To get what you asked for, you can use dl = {D[g[x, y], x], D[g[x, y], y]}; Through @ dl[0, 0] However, as noted by @Kuba, you probably want something like ClearAll[foo]; foo = Through@(Function[{x, y}, #] & /@ dl)@## &; foo[0, 0]

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.

3

The problem is caused by ambiguity in the control-inferencing logic used by Manipulate and Control in the absence of an explicit control type specification. A Manipulate value with a list of pairs is a valid specification for a Slider, SetterBar, PopupMenu or InputField. Manipulate arbitrarily chooses to use a slider. Mathematica uses various heuristics ...

3

Note that you are using :=, also known by its FullForm name SetDelayed, to define your functions. According to the Documentation Center page for :=: lhs := rhs assigns rhs to be the delayed value of lhs. rhs is maintained in an unevaluated form. When lhs appears, it is replaced by rhs, evaluated afresh each time. This means that Sqrt[g[x]] is ...

3

We can use some of Mathematica's built-in tracing facilities to help us answer this question. Let's start by ensuring that the symbols we are about to use carry no extraneous definitions: ClearAll[f, g, x] Now, we'll establish the definitions from the question: g[x_] := x^2 f[x_] := Sqrt[g[x]] We can turn on selective tracing of some functions to see ...

3

This is an extension to Szabolcs' answer. I would have explained it in 2nd comment to his answer, but it is a little too complicated to be a comment. There is another complication in regard to reproducing this problem. It is essential that the assignment a = {Missing[], 1, 2, 3} ; be evaluated before a DeleteMissing expression is successfully evaluated ...

2

In addition to @belisarius' solution, you might want to look at StringForm Clear[f] f[c_, d_, z_] = c + d z; (* either Set or SetDelayed works *) s = Solve[{f[c, d, 1] == 2, f[c, d, -1] == 1}, {c, d}]; StringForm["c = 1, d = 2", c, d] /. s[[1]]

2

You can identify the problem by performing the steps in your function one at a time for theta = .1 and phi = 0.. {c1, c2, c3} = 1 - 3 Sin[0.1]^2 Cos[0 - 2 Pi (# - 1)/3]^2 & /@ {1, 2, 3} {* {0.9701, 0.992525, 0.992525} *} Phi = Sqrt[((c2 + c3)^2 - c1^2)/(4 c2 c3)] {* 0.87245 *} PhiPr = ((c3 - c2)/c1) Phi {* 0. *} Because 0 <= Phi^2 <= 1 is ...

2

I suspect that you can obtain what you need by following way: list = {{1, 2}, {3, 4}, {5, 6}}; Manipulate[list[[i]], {i, 1, Length@list, 1}] This code always gives you the element (sublist) of initial list.

2

You may be thinking of another idiom. http://en.wikipedia.org/wiki/Do_while_loop#Equivalent_constructs m = 0; While[True, m = m + 1; If[Not[m <= 50], Break[]]; p = m]

2

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.031424., 0.31424., 3.1424., 31.424., 314.24.] Related Q&A's: Meaning of backtick in ...

2

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 ...

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 ...

2

Like k_v also proposed Refine can be used. ClearAll[f, g, h]; g[x_] := x^2; f[x_] := Sqrt[g[x]]; h[x_] = Block[{x}, Refine[f[x], x > 0]]; Trace@Map[h, Range[100]] h[x]===x returns True

2

You can answer your question by using the built-in function Trace. g[x_] := x^2 f[x_] := Sqrt[g[x]] Trace[Map[f, Range[3]]] { {Range[3], {1, 2, 3}}, f /@ {1, 2, 3}, {f[1], f[2], f[3]}, {f[1], Sqrt[g[1]], {g[1], 1^2, 1}, Sqrt[1], 1}, {f[2], Sqrt[g[2]], {g[2], 2^2, 4}, Sqrt[4], 2}, {f[3], Sqrt[g[3]], {g[3], 3^2, 9}, Sqrt[9], 3}, {1, 2, 3} } From ...

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