Tag Info

Hot answers tagged

14

Introduction This post is long overdue as I have been repeatedly asked to explain code of mine containing these things. As I see increased use of this construct by others perhaps it is past due also. SparseArray objects can behave as functions accepting certain arguments to return internal data or efficiently return data in certain forms. These are known ...


6

If you have a list of variables stored in vars in the desired order and expr is the function's formula, then f = Function @@ {vars, expr} will define a function for you. If you're content with the variables being in their sorted order and the expression expr is polynomial-ish (test Variables[expr] first), then f = Function @@ {Variables[expr], expr} ...


6

It was actually a lot easier than I thought f = Function @@ {vars, expr}


6

This is a comment rather than an answer, but it grew too long for the comment box, and I wanted to show graphics, so I'll leave it here in hopes that someone better versed in the inner workings of MMA might explain this behavior. I am using your definition of the wrapper function pp. First of all, I get a slightly different version of the "wrong" function: ...


6

evenFQ[f_] := Simplify[f[t] - f[-t]] === 0 oddFQ[f_] := Simplify[f[t] + f[-t]] === 0 Examples: ef[x_] := x^2 of[x_] := x^3 evenFQ/@ {ef, of} {True, False} oddFQ/@ {ef, of} {False, True} evenFQ /@ {# &, Im, Sin, Tan, Sinh, Erf} {False, False, False, False, False, False} oddFQ /@ {# &, Im, Sin, Tan, Sinh, Erf} { True, ...


5

As MarcoB posted before me this has to do with evaluation differences. Simply setting HoldFirst on pp produces the original plot: SetAttributes[pp, HoldFirst] pp[ψ_, options___] := ParametricPlot[{r, ψ}, {r, -1, 1}, options, PlotRange -> {Automatic, 1.05 {-1, 1}}] pp[ZernikeR[100, 0, r]] You will want this attribute anyway as without it the ...


5

Rather than imposing x>0 one can also do FullSimplify[ ForAll[x, myOddFunction[x] == myOddFunction[-x]]] which yields False.


4

You need Simplify with an assumption: myOddFunction[x_] := x^3; Simplify[ Equal[myOddFunction[x], myOddFunction[-x]], x > 0 ] False Refine also works in this case, again with the appropriate assumption: Refine[Equal[myOddFunction[x], myOddFunction[-x]], x > 0] False


4

f1 = Which[# < 10, ## &[#, 0], # > 10, ## &[0, #]] &; f2 = ## & @@ Which[# < 10, {#, 0}, # > 10, {0, #}] &; f3 = ## & @@ {Append, Prepend}[[1 + Boole[# > 10]]][{#}, 0] &; f4 = ## & @@ {Identity, Reverse}[[1 + Boole[# > 10]]][{#, 0}] &; f5 = Which[# < 10, {#, 0}, # > 10, {0, #}] /. List -> ...


4

Here's a way to define a function that does your computation: With[{WN = WhiteNoiseProcess[NormalDistribution[0, 10]]}, aV[m_] := Module[{data, points, yBinLst, meanLst}, data = RandomFunction[WN, {1, 10000}]; points = data["Values"]; yBinLst = Partition[points, m]; meanLst = Mean /@ yBinLst;; Total[Differences[meanLst]^2]/(2 ...


4

Using the option Evaluated->True or wrapping the first argument of Plot with Evaluated gives a 100x speed-up: ls1[t_] := Quantity[10, "Nanometers"]/t Plot[ls1[Quantity[t, "Seconds"]]/Quantity[1, "SpeedOfLight"], {t, 0, 10}] // Timing ls2[t_] := Quantity[10, "Nanometers"]/t Plot[ls2[Quantity[t, "Seconds"]]/Quantity[1, "SpeedOfLight"], {t, 0, 10}, ...


3

Edit: see the bottom of this post for the best solution. The documentation for CoefficientList says: The dimensions of the array returned by CoefficientList are determined by the values of the Exponent[poly, vari]. ser1 = Series[ArcTan[x]/(1 - x^2), {x, 0, 10}]; ser2 = Series[ArcTan[x]/(1 - x), {x, 0, 10}]; Exponent[ser1, x] Exponent[ser2, x] 9 ...


1

Simplify[(Cos[2*a + b + c]*Tan[a + 2*b + 2*c])/ Sin[(b + c - a)/2]] /. (b -> Pi - a - c) // TrigExpand Tan[a] Simplify[(Sin[(6*Pi)/5 + x])^2 + (Sin[(4*Pi)/5 - x])^2 // Simplify, Pi/5 + x == ArcCos[m^-1]] // Together (2*(-1 + m^2))/m^2


1

Eliminate the options and impose a reasonable WorkingPrecision: Clear[pp]; pp[\[Psi]_] := ParametricPlot[{r, \[Psi]}, {r, -1, 1}, PlotRange -> {Automatic, 1.05 {-1, 1}}, WorkingPrecision -> 200]


1

Supposing that you want a DownValues definition rather than a Function you could use: (* with your expression assigned to expr *) (x \[Function] x_) /@ Variables[expr]; f[Sequence @@ %] = expr;


1

f[ω0_, α00_, α01_, α02_, α10_, α11_, α12_, α20_, α21_, α22_, β01_, β02_,β11_, β12_, β21_, β22_] := ... where ... is the list in your OP. N.B. you're missing ω1 as an argument, I assume that's intentional...



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