11

ClearAll[allCompositions] allCompositions[a_] := Through @ (Permutations @* Composition)[##] @ a &; Examples: allCompositions[x][f1, f2, f3] {f1[f2[f3[x]]], f1[f3[f2[x]]], f2[f1[f3[x]]], f2[f3[f1[x]]], f3[f1[f2[x]]], f3[f2[f1[x]]]} allCompositions[x] @@ {f1, f2, f3} {f1[f2[f3[x]]], f1[f3[f2[x]]], f2[f1[f3[x]]], f2[f3[f1[x]]], f3[f1[f2[x]]], f3[f2[...


10

Composition[##][x] & @@@ Permutations[{f1, f2, f3}] {f1[f2[f3[x]]], f1[f3[f2[x]]], f2[f1[f3[x]]], f2[f3[f1[x]]], f3[f1[f2[x]]], f3[f2[f1[x]]]}


7

When you solved it analytically by Solve, I think you got the warning message: Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information. So it is not guaranteed that all the analytic solutions are obtained in this way. (Note that the Lambert W function is multivalued.) As ...


7

First of all, the NDSolve solution can be further improved: k = 5.; tf = 3.; c[θ1_?NumericQ, θ2_?NumericQ] := NIntegrate[(Sin[θ1 + t]^2. Cos[θ2 + t])/E^t, {t, 0., tf}, Method -> {Automatic, SymbolicProcessing -> 0}]; sol = NDSolve[{θ1'[t] == θ2[t]/E^(Sin[t]/10.) + c[θ1[t], θ2[t]], θ2'[t] == -k Sin[θ1[t]]/E^(Sin[t]/10.), ...


6

Clear["Global`*"] tf = s^2/(s^2 + 2 s + 5); Manipulate[ Show[ ComplexPlot3D[tf, {s, -2 - 3 I, 1/4 + 3 I}, MeshFunctions -> mf, MeshStyle -> {Black, Darker[Green]}, Mesh -> 9, PlotPoints -> 50, MaxRecursion -> 5, PlotLegends -> BarLegend[Automatic, LegendLabel -> HoldForm[Arg[tf]]], PlotRange -&...


6

May be like this. tf = s^2/(s^2 + 2 s + 5); mag = Abs[ComplexExpand[tf /. s -> σ + I*w]]; SetOptions[Plot3D, BoundaryStyle -> None, PlotRange -> {0, 8}, ViewPoint -> {2.54, 1.27, 1.8}, BoxRatios -> {1, 1, 1}, ClippingStyle -> Yellow]; fig1 = Plot3D[mag, {σ, -2, 0}, {w, -3, 3}, MeshFunctions -> {#3 &}, MeshShading -> {...


5

Still another option is Factor[u /. x^n_ -> y^(n/4)] /. y -> x^4 (* (-3 + x^4) (-1 + x^4) (1 + x^4) *)


5

As mentioned in the comments, it's a matter of precedence. When you're not sure about the precedence, just click n times on the code, and the code piece will be selected outwards according to the precedence: As shown in the GIF above, after clicking on & 3 times, _?(#[[1 ;; 6]] == {0, 0, 0, 0, 0, 0}) & is selected i.e. the whole _?(#[[1 ;; 6]] == {0,...


4

Here is one approach to teaching Solve about inert notational constructs: $Notations = ( Subscript | Superscript | Subsuperscript | SubPlus | SubMinus | SubStar | SuperPlus | SuperMinus | SuperStar | SuperDagger | Overscript | Underscript | Underoverscript | OverBar | OverVector | OverTilde | OverHat | OverDot | UnderBar ); Unprotect[Solve];...


4

There are multiple improvements for your code, the most obvious ones being you could use Grad and Curl to compute {ax,ay,az} and {fx,fy,fz} in one line each, and also use Normalize for {zup0,zdo0}. Combining all of this, your code can be "vectorized" to be much more concise and mathematical-looking. You also may want to use Simplify to simplify ...


4

You can define more than one interface for a function: myFunc[n_Integer, list_?VectorQ, i_] := Module[{x, y}, x = ToExpression["x" <> IntegerString[{i}]]; y = ToExpression["y" <> IntegerString[{i}]]; restoffunction[n, list, x, y]] myFunc[n_Integer, list_?VectorQ] := Module[{x, y}, x = ToExpression["x"]; y =...


3

We can (ab)use the automatic expansion of OptionValue into its three-argument-form, which works even inside rules: Options[func] = {"opt" -> None}; {func["opt" -> 1], func[]} /. func[OptionsPattern[]] :> OptionValue["opt"] (* {1, None} *) Now, for your example: First, we define iExpandOptionValue that takes expands ...


3

It would be preferable if you limited the number of functions being displayed to one or at most two. You can do this with Manipulate Clear["Global`*"] freq[a_, b_, t0_, tr_, s_] = LaplaceTransform[ a + ((b - a)/tr t - (b - a)/tr t0) (UnitStep[t - t0] - UnitStep[t - (t0 + tr)]) + (b - a) UnitStep[t - (t0 + tr)], t, s] // ...


2

"Radians" do have a dimension in Wolfram Language ("AngleUnit"), and "Revolutions" have an independent physical dimension ("RevolutionUnit"). There is a "FullAngle" unit, which corresponds to 360 degrees, which is equivolent to the colloquial notion of 1 revolution = 2 Pi radians: In[5]:= UnitDimensions["...


2

Try defining this recursively: MyLimit[expression_, {initialVariables__, x_ -> x0_}] := Limit[MyLimit[expression, {initialVariables}], {x -> x0}] MyLimit[expression_, {x_ -> x0_}] := Limit[expression, {x -> x0}]


2

f[i__] := KroneckerProduct @@ PauliMatrix[{i}] f[1, 2, 3] == KroneckerProduct[PauliMatrix[1], PauliMatrix[2], PauliMatrix[3]] (* True *) Do you need special cases for zero or one Pauli matrix, or do these cases never occur for you?


2

What you're asking is called Optional. You can provide a default value, then inside your function check whether the default value is passed or not. Read here Optional and Default Arguments for more information. Code Here, the default value is Missing["notFound"]. z introduced to hold natural value for your operation ("") and if i is not ...


2

Why not AbsArg?: (320 Cos[1000 t])/12641 + I (-((316 Cos[1000 t])/12641) + (320 Sin[1000 t])/12641) + (316 Sin[1000 t])/12641// AbsArg // ComplexExpand[#, TargetFunctions -> {Re, Im}] & // #[[1]] Exp[I #[[2]]] & (* E^(I ArcTan[(320 Cos[1000 t])/12641 + (316 Sin[1000 t])/ 12641, -((316 Cos[1000 t])/12641) + (320 Sin[1000 t])/12641]) ...


2

You could do a SolveAlways to get the values a[i] below, provided you know in advance the number of factors: prod[x_, n_] := Product[x^4 + a[i], {i, n}] sol = SolveAlways[x^12 - 3 x^8 - x^4 + 3 == prod[x, 3], x]; prod[x, 3] /. sol[[1]] (* (-3 + x^4) (-1 + x^4) (1 + x^4) *)


2

This can be done in several ways. How about this: First, u = x^12 - 3 x^8 - x^4 + 3; u1 = Factor[u] (* (-1 + x) (1 + x) (1 + x^2) (-3 + x^4) (1 + x^4) *) Then Simplify[Drop[u1, -2]]*Drop[u1, 3] (* (-3 + x^4) (-1 + x^4) (1 + x^4) *) Have fun!


1

First, a note regarding noSymbol: You can more easily implement it using FreeQ: symbols = Alternatives[basisElement]; noSymbol := FreeQ[symbols] Also, you don't need to define both f[a_ * v_] and f[v_ * a_], since Times is Orderless. As for the actual question: I don't see any reason why this shouldn't be done, in fact, I've used very similar functions in ...


1

For comparative timings, starting with a fresh kernel: $Version (* "12.3.0 for Mac OS X x86 (64-bit) (May 10, 2021)" *) Clear["Global`*"] HighWaterMarks[1][s_?VectorQ] := Split[FoldList[Max, s]][[All, 1]]; HighWaterMarks[2][s_?VectorQ] := Drop[Fold[If[Last[#1] < #2, Append[#1, #2], #1] &, {-∞}, s], 1]; HighWaterMarks[3][s_?...


1

Tried this: k = 2; EE = 0; \[Epsilon] = 1; poly[r_] := r^4/pyz^2 (pt^2 + (r^((-2 (4 k^2 - 3 k + 2))/((k - 1) (2 k - 1))) ((pt^2 - (pyz^2 + pyz^2) - \[Epsilon]* r^2) r^((4 k)/(k - 1)) + (pyz^2 + pyz^2 + \[Epsilon]*r^2)*r^(5/(k - 1))) + EE)); atLeastOne = Exists[r, r > 0 && poly[r] == 0]; atLeastTwo ...


1

You are getting there! All you need is a space between your Pi and your x. As it is you have a Pix which is the name of a variable. Pi x is the same as Pi*x. If you want to generalize this with mass. You can do this: y[m_, t_]: = (3 Pi)^(1/3) (m t)^(3/2)/2^(2/3) I recommend that you view your functions symbolically when possible. Your function y[x_] := \[...


1

Integrate localizes its variables. Therefore the variables kx,ky,kz in integrand and the integration variables of NIntegrate are not the same. What you can do is to write integrand as a function like: integrand[kx_, ky_, kz_] = ax fx + ay fy + az fz; result = NIntegrate[ integrand[kx, ky, kz], {kx, 0, 2 Pi}, {ky, 0, 2 Pi}, {kz, 0, 2 Pi}] However, there is ...


1

Since you did not show the result of your execution, I think people misunderstood your situation. The problem is not in the inequality of the two function forms. The problem is that the functions kp and kpp, when operated on an array of complex numbers (actually, the real and complex parts, separated), behave differently. I could not find more detail reasons,...


1

Consider: kp[k1, k2] == kpp[k1, k2] As you see, the numerator are identical, therefore the difference must come from the denominator. Further note that array and also the arguments are vectors. Now investigate how Norm and Abs behave with vector arguments. E.g.: Norm[{1,1}] Abs[{1,1}] Norm gives a scalar, Abs a vector! Now if we simplify array to: array = ...


1

Clear["Global`*"] k[k1_, k2_] := {Sqrt[3]/2 k1, k1/2 + k2, 0}; kp[k1_, k2_] := (#/Norm[#]) &[k[k1, k2][[1]] + I k[k1, k2][[2]]] kpp[k1_, k2_] := (k[k1, k2][[1]] + I k[k1, k2][[2]])/ Abs[k[k1, k2][[1]] + I k[k1, k2][[2]]] Test whether the functions are equivalent array = {a, b}; FullSimplify[kp[c (array + d), c (-array + d)]] === ...


1

I desperately needed this capability and found Mathematica's string formatting incredibly obtuse and hard to remember. Therefore, I reimplemented, as well as I could, sprintf in https://github.com/evanberkowitz/mma-sprintf The implementation is too long to present here; instead I present the help ?sprintf gives %[flags][width][.precision][length]type ...


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