Tag Info

New answers tagged

1

Another replacement version: expr /. (x_ &) :> x /. x_ :> (x &)


2

Merely my own variation of the existing answer by mfvonh: expr = 1/4 Fp (2 Fp - Fp^3/Fm^2 + 4 Fm Derivative[1][Fm] Derivative[1][Fp]); Fm = Sin[#] &; Fp = Sin[#] Cos[#] &; FullSimplify[expr /. (x_ &) :> x] Function @@ {%} 1/32 (3 + 7 Cos[2 #1]) Sin[2 #1]^2 1/32 (3 + 7 Cos[2 #1]) Sin[2 #1]^2 &


0

Why not just a simple replacement rule? mergeF[expr_] := expr /. {((Cos[#1] &) (Sin[#1] &)) :> (Sin[#] Cos[#] &)} mergeF[Fm Derivative[1][Fm]] (* Sin[#1] Cos[#1] & *) mergeF[1/4 Fp (2 Fp - Fp^3/Fm^2 + 4 Fm Derivative[1][Fm] Derivative[1][Fp])]


1

Postfix-Definition Clear@"`*" Sin*Cos // f[r_] := Sin[r]*Cos[r] Sin*Cos // f[Pi/7] (* out *) Cos[Pi/7] Sin[Pi/7] Prefix-Definition Clear@"`*" g[r_][Sin*Cos] := Sin[r]*Cos[r] g[Pi/11][Sin*Cos] (*out*) Cos[Pi/11] Sin[Pi/11] Just 1 letter more to type


4

There may be a better way to do this, but perhaps 4 Fm Derivative[1][Fm] /. Function[b_] :> b // Evaluate // Function 4 Cos[#1] Sin[#1]& 1/4 Fp (2 Fp - Fp^3/Fm^2 + 4 Fm Derivative[1][Fm] Derivative[1][Fp]) /. Function[b_] :> b // Evaluate // Function 1/4 Cos[#1] Sin[#1] (2 Cos[#1] Sin[#1]-Cos[#1]^3 Sin[#1]+4 Cos[#1] Sin[#1] ...


4

The generalized definition of partial fails because the generated function looks like this: partial[accumulate, $myAccumulator] (* accumulate[Sequence@@Quiet[Join[$myAccumulator,##1]]]& *) Note how accumulate will be called with only a single argument. Since accumulate is HoldFirst, that argument will not be expanded into a sequence of arguments and ...


4

Maybe I don't understand what you're trying to do, but... q = <|elems -> ConstantArray[Null, 4]|> q[[1, 2]] = 42; q <|elems -> {Null, 42, Null, Null}|> q[[Key[elems], 4]] = 99; <|elems -> {Null, 42, Null, 99}|> So whether you set by position or Key it works.


3

I had a flash of insight and did the following. Notice particularly the necessary RuleDelayed on the elems tag in the association: q = Module[{storage = ConstantArray[Null, 4]}, <|elems :> storage, set -> ((storage[[#1]] = #2) &)|>]; q[set][2, 42]; q[elems] {Null, 42, Null, Null}


4

As others have noted, it's not entirely clear what you want. A possibility is you want to "simplify" the rules so that, on application, all four variables would give numbers. I'll show a way to obtain that and possibly you can modify to suit the actual need. We'll start with the lists of rules and create defining polynomials and also extract the variables ...


1

Expanding on Mr.Wizard's answer, the side effects can be eliminated simply be doing the work inside a function rather than at top-level. list1 = {a -> b + c, d -> b + c}; list2 = {b -> 1, c -> 1}; f[list1_, list2_] := {list1, list2} /. list2 // Values f[list1, list2] {{2, 2}, {1, 1}} Column@{{a, b, c, d}, list1, list2}


3

Update Following the new examples you gave I believe this does what you want: Thread[lists[[All, 1]] -> (lists[[All, 2]] //. lists)] Output: {v[4] -> 2000000000000, v[6] -> 4.92958*10^12, v[15] -> 100000000, v[31] -> 6.*10^11, v[32] -> 0.05, v[33] -> 2000000000000, v[35] -> 400000000000, v[41] -> 1.6*10^12, v[45] -> 1, ...


3

You can "inject" that variable by grabbing it with With. It then gets put into the body of the With verbatim, hence it gets inside the Function in the desired form. f2[expr_] := With[{var = First@Variables[expr]}, expr /. var -> # &] f2[x^2] (* Out[79]= x^2 /. x -> #1 & *) This can also be done in the way you had tried, with a bit of work ...


1

The random crashing of the kernel seems to arise due to your definition of evolve and fct. I'll keep h[x_, p_] := -x^2 + p^2 + x^4; and change the definition of evolve to evolve[xini_, pini_, time_] := Module[{x, p}, Hold[{x[time], p[time]} /. First@NDSolve[{x'[t] == p[t], p'[t] == -x[t], x[0] == xini, p[0] == pini}, {x, p}, ...


4

Taking the question at face value, I think the answer is yes. A While loop While[test, body] evaluates test then body until test fails to give True. This can be implemented in NestWhile by putting test and body into Functions: NestWhile[body &, Null, test &] For example the following both do the same thing: i = 0; While[i < 10, i++]; i = 0; ...


0

If I follow your description correction you want to restrict TrackedSymbols to only those directly controlled by Manipulate. This means that when a non-tracked Symbol definition is modified the Manipulate will be "out of date" until you move a slider, etc. fn = Sin; Manipulate[Plot[fn[x (1 + a x)], {x, 0, 6}], {a, 0, 2}, TrackedSymbols :> {a}] Now ...


1

Manipulate is based on Dynamic, so if output of Manipulate is already created, then it will dynamically update every time when related variables have changes. If you want to stop such behavior of Mathematica, you need to stop dynamic update temporary. And Start it again when it is needed. You can do it through GUI or by usual Mathematica command ...


4

Mathematica embraces the notion of canonical form. Internally it wants all expressions to be reduced to their canonical forms. Times[x, x] is not a canonical form, so it gets reduced to Power[x, 2], which is. I share Mr.Wizard's occasional frustration over the choices of canon made by Wolfram Research, but I think it is far too late to expect any change. ...


7

We can use this function to see that the conversion is not made during parsing: parseString[s_String, prep : (True | False) : True] := FrontEndExecute[FrontEnd`UndocumentedTestFEParserPacket[s, prep]] parseString["x x"] {BoxData[RowBox[{"x", "x"}]], StandardForm} We can use this to see that the conversion does not take place while converting boxes ...


4

To compute $\nabla^nr$ for arbitrary integer $n$, you can use the built-in tensor derivative syntax. For example, you can compute the second-derivative $\nabla^2r$ using r = Sqrt[x^2 + y^2 + (z - a)^2]; X = {x, y, z}; D[r, {X, 2}] To get an answer in terms of $r$, you can sort of cheat your way to the correct answer via the following modification: r = ...


1

r[x_, y_, z_] = Sqrt[x^2 + y^2 + (z - a)^2]; D[r[x, y, z], #] & /@ {x, y, z} {x/Sqrt[x^2 + y^2 + (-a + z)^2], y/Sqrt[ x^2 + y^2 + (-a + z)^2], (-a + z)/Sqrt[x^2 + y^2 + (-a + z)^2]} or more simply, % == D[r[x, y, z], {{x, y, z}}] True %% == {x, y, z - a}/r[x, y, z] True EDITED to add higher order partial derivatives Second ...


1

TraditionalForm@FullSimplify@Exp[FullSimplify@PowerExpand[ Log[((Ft Bcr)^(2 p + 4)*Ft^(23 p - 4))/(Bcr^(1/(2.5 p - 4))* Ft^((24 p + 4)/(3 p - 1)))^(3 p - 6)]]] $\text{Ft}^{p+\frac{60}{3 p-1}+36} \text{Bcr}^{-\frac{1.2}{4.\, -2.5 p}+2. p+2.8}$



Top 50 recent answers are included