Tag Info

Hot answers tagged functions

19

Max[StringLength@Names["System*"]] 38 Select[ Names["System*"], 38 == StringLength[#] &] {"MultivariateHypergeometricDistribution"} As far as I can say there is no limit for lengths of symbol names, besides that of the memory limitation.

12

The term pure function used in Mathematica is not being used in the same sense as the cited Wikipedia article. In Mathematica it refers to an anonymous function. In the Wikipedia article it is a term extracted by analogy from the increasingly popular term "purely functional" which refers (mainly) to deterministic programming free of side-effects. The ...

11

Which documented Mathematica function has the longest name I assume then you want all of Mathematica, which includes all standard packages and contexts that come in the installation and not just in the System context. I just run some code I have and added a check to obtain this information. Here is the table. According to this: ...

10

For your particular example, Thread[f[g[x]], g] Generally, we can think of Thread as of a function to exchange heads between first two levels. For more complex rearrangements, you may need to use replacement rules and other methods, described in other answers.

9

Here's a way that doesn't mess with an important system function: Clear[a, times]; m = Array[a, {3, 3}]; TensorContract[ Outer[times, Sequence @@ m] \[TensorProduct] LeviCivitaTensor[Length[m], List], Table[{i, i + Length[m]}, {i, Length[m]}]] (* times[a[1, 1], a[2, 2], a[3, 3]] - times[a[1, 1], a[2, 3], a[3, 2]] - times[a[1, 2], a[2, 1], a[3, 3]] + ...

9

Here is what I do in such cases: ClearAll[g, f]; Options[f] = {optA -> 1, optB -> 1, optC -> 1}; f[x_, opts : OptionsPattern[]] := {OptionValue[optA], OptionValue[optB], OptionValue[optC]} Options[g] = {optA -> 0, optB -> 0}; g[x_, opts : OptionsPattern[{g, f}]] := f[x, opts, Sequence @@ Options[g]] In other words, only define options ...

8

In biref, clear denominators and form a lexicographic Groebner basis with variable ordering x>y. Now throw out anything with x in it. eqns = {7*x == -(x*y) + (9*y^4)/(1 + 3*x)^2, 5*y == -2*x^2 + (6*y^3)/(1 + 3*x)}; rats = Subtract @@@ eqns; polys = Numerator[Together[rats]] (* Out[112]= {7 x + 42 x^2 + 63 x^3 + x y + 6 x^2 y + 9 x^3 y - 9 y^4, 2 ...

7

Just for fun: f[a_, t_] := a {t - Sin[t], 1 - Cos[t]} Manipulate[ ParametricPlot[{f[1, 4 t], f[2, 2 t], f[4, t]}, {t, 0, 4 Pi}, PlotStyle -> {Red, Green, Blue}, Epilog -> {{Orange, Circle[{4 p, 1}, 1], Black, PointSize[0.015], Point[f[1, 4 p]]}, {Orange, Circle[{4 p, 2}, 2], Black, PointSize[0.015], Point[f[2, 2 p]]}, {Orange, ...

7

In principle you can redefine safely a native function inside Block and given that Det uses Times for symbolic matrices then Block[ {Times = f}, Det[{{a, b}, {c, d}}] ] f[a, d] + f[-1, b, c] As pointed out by @Kuba and @Jens there are several limitations. A better solution would be this: newDet[m_, f_] := Activate@(Block[{ms = Length[m], Times = ...

6

#[[0]] /@ #[[1]] &@ f[g[x]] (* g[f[x]] *)

5

Maybe MapThread gives the levelspec control you need: lst = {{{a, b}, {c, d}}, {{w, x}, {y, z}}}; g @@ MapThread[f, lst, 1] (* or just g @@ MapThread[f, lst] -- thanks: Mr.W *) (* g[f[{a,b},{w,x}],f[{c,d},{y,z}]] *) g @@ MapThread[f, lst, 2] (* g[{f[a,w],f[b,x]},{f[c,y],f[d,z]}] *) or, g @@ Thread[f @@ lst] (* g[f[{a,b},{w,x}],f[{c,d},{y,z}]] *) or ...

5

You can use Fold instead: f[n_Integer] := Fold[#2/(1 + #) &, n, Reverse@Range[n - 1]] f[3] $\frac{1}{1+\frac{2}{1+3}}$ It not very useful analytically, but it allows you to invoke the CPU gods: f /@ Range[50] // ListLinePlot[#, PlotRange -> All] &

5

No, it is not doing a Gram-Schmidt procedure. One way to note that this is distinct from Gram-Schmidt is that Gram-Schmidt produces an orthonormal basis, whereas the example outputs in the Documentation Center page for LatticeReduce are neither normalized nor orthogonal. Instead, LatticeReduce returns a basis $B$ comprised of linear combinations of integer ...

5

Taking the problem a bit more generally we might use a decomposition function: de[p : a_@_ | _] := {a, ## & @@ de @@ p} Then on any expression with one argument at each level: b[c[d[e[x]]]] // de {b, c, d, e, x} Reorder however we please: %[[{3,1,4,2,5}]] {d, b, e, c, x} And put it back together: Compose @@ % d[b[e[c[x]]]]

4

dist = MultinormalDistribution[ {0, 0}, {{1, 0}, {0, 1}}]; PDF[dist, {x, y}] E^((1/2)*(-x^2 - y^2))/(2*Pi) CDF[dist, {x, y}] (1/4)*Erfc[-(x/Sqrt2)]*Erfc[-(y/Sqrt2)] The inverse CDF is not unique. To simplify the problem I will find the inverse CDF with y == x Show[ ContourPlot[ CDF[dist, {x, y}], {x, -3, 3}, {y, -3, 3}, Contours ...

4

What about switch[f_[g_[x_]]] := f[g[x]] /. {f -> g, g -> f}

4

This probably doesn't address the full scope of your question but for the particular example you could use MapThread and Apply: ex1 = {{a, b}, {c, d}}; ex2 = {{w, x}, {y, z}}; g @@ MapThread[f, {ex1, ex2}] g[f[{a, b}, {w, x}], f[{c, d}, {y, z}]] Or Transpose and Apply: g @@ f @@@ ({ex1, ex2}\[Transpose]) g[f[{a, b}, {w, x}], f[{c, d}, {y, z}]]

3

ClearAll[a, b, c, x, y, z, list, func]; list = {{x1, y1, z1}, {x2, y2, z2}, {x3, y3, z3}}; func[x_, y_, z_, a_, b_, c_] := {a, b, c}.{x, y, z} func[##, a, b, c] & @@ list[[1]] (* a x1+b y1+c z1 *) func[## & @@ #, a, b, c] &@list[[1]] (* a x1+b y1+c z1 *) func[##, a, b, c] & @@@ list (* {a x1+b y1+c z1,a x2+b y2+c z2,a x3+b y3+c z3} *) ...

3

I'm not sure I understand what you are doing but the plots plat should be simple. We put all your results in a Table using ParallelTable to use all available cores in your CPU. data = ParallelTable[ Block[ {r = f[x, cb], fmax, xmax}, fmax = First[r]; xmax = (x /. Last[r]); {cb, xmax, fmax} ], {cb, 0, 0.3, 0.3/20}]; TableForm[N@data, ...

3

LyapunovSolve and DiscreteLyapunovSolve solve several equations Lyapunov, Sylvester, Stein, generalized versions, etc., and as such there is no one standard form. Since they are linear solvers their design was based on the precedent set by LinearSolve. For $\dot{x}=A.x$ to be stable, $P=\text{LyapunovSolve}\left[A^{\mathsf{T}},-Q\right]$ has to be positive ...

2

As you're trying to represent things that aren't functions, I suggest to change your representation to vectors (affine): (* a few functions *) line[{v_List, d_List}, a_] := a v + d circle[{c_List, r_}, t_] := c + r {Cos@t, Sin@t} intersection[{v_List, d_List}, {c_List, r_}] := Solve[line[{v, d}, a] == circle[{c, r}, t], {t, ...

2

This works much faster: f[r_, z_, from_, to_] := (int = Integrate[r/((l - z)^2 + r^2)^(3/2), z]; Limit[int, z -> to] - Limit[int, z -> from]) sol = f[r, z, 0, L0] The reason is takes much longer when doing definite integration directly is due to assumptions. If you gives assumptions, then it will be fast also. Try ...

2

I haven't yet tried to imagine an algorithm for your problem but here is a visualization that might help you approach it. pairs[ls_List] := Join @@ Tuples /@ Subsets[ls, {2}]; plot[ls_List, set_List] := ArrayPlot[ Outer[SubsetQ, set, pairs @ ls, 1] // Boole, FrameTicks -> All, FrameLabel -> {"Tuples", "Pairs"} ] If you are not using ...

2

Interpolation in given range: x = Range[62, 70]; y = Range[10, 90, 10]; f = Interpolation@Thread@{x, y}; f'[x0] /. x0 -> 65 10 dom = First@f["Domain"]; Show[Plot[f[x], {x, First@dom, Last@dom}], ListPlot[Thread@{x, y}, PlotStyle -> Red]] Interpolation to produce a usual polynomial: g[xx_] = InterpolatingPolynomial[Thread@{x, y}, xx]; ...

2

It seems to me that this is a special case of a graph connectivity situation. That is, the individual elements in foo can be seen as vertices, while foo[[i]] for i=1,2,3 can be seen as layers in a (directed) net. This can be visualized as: edges = {a -> c, a -> d, a -> e, a -> f, b -> c, b -> d, b -> e, b -> f, c -> x, d ...

1

I'm afraid I don't know what realized covariance means. Perhaps the easiest solution is to use RLink and directly use the R implementation. Here are some links to the documentation to get you started. http://reference.wolfram.com/language/RLink/guide/RLink.html http://reference.wolfram.com/language/RLink/tutorial/UsingRLink.html

1

Here is what I believe you are seeking: ParametricPlot[{{1 (Theta - Sin[Theta]), 1 (1 - Cos[Theta])}, {2 (Theta - Sin[Theta]), 2 (1 - Cos[Theta])}, {4 (Theta - Sin[Theta]), 4 (1 - Cos[Theta])}}, {Theta, -10 Pi, 10 Pi}, AspectRatio -> .5, PlotRange -> {{-8 Pi, 8 Pi}, Automatic}] The resulting Plot:

1

This is not an answer to your question (hence the community tag) since I do not know why Integrate does not solve this, but to point out that the command Int solves this instantly with no problem. This is using Albert Rich Rubi package: ShowSteps = False; Int[(1 + (1 + 1/(2*Sqrt[x]))/(2*Sqrt[Sqrt[x] + x]))/(2*Sqrt[x + Sqrt[Sqrt[x] + x]]), x]

1

There are several little issues that conspire to trip up your code here and there. Let me just point out a couple of the major things to think about. First, keep clearly in mind the difference between a function f and the expression f[t]. I know from teaching mathematics that these tend to get conflated in ordinary conversation, but you cannot get away ...

1

Not sure if this is what you want, but this is much faster: ClearAll[a, c, phi, t1, psi, g]; a = 0; c[t_] := t*{Cos[t], Sin[t]} phi = Integrate[Sqrt[c'[t].c'[t]], {t, a, t1}, Assumptions -> t1 \[Element] Reals && t1 > 0]; psi = InverseFunction[Function[{t1}, Evaluate@phi]]; g[s_] := g[s] = c[psi[s]] ParametricPlot[g[x], {x, 0, 40}, PlotRange ...

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