Tag Info

New answers tagged

0

This is merely to participate. Just bookending and removing doubled ups... f[x_] := Fold[#1 /. #2 &, Join[{-Infinity}, x, {Infinity}], {{-Infinity, -Infinity, m___} :> {m}, {m___, Infinity, Infinity} :> {m}}] so, w = {{1, 2, 3}, {-∞, 1, 2}, {1, 2, ∞}, {-∞, 1, 2, ∞}, {-∞, ∞}, {∞}, {-∞}, {}} f /@ w yields: {{-∞, 1, 2, 3, ∞}, {1, ...


6

The OP's (current) definition of ncalc is unreadable and unsalvageable, so I made one up from pieces of the code. ncalc = Piecewise[{ {-21. + 294. u - 1029. u^2, u < 1/7}, {2. v (131.25 - 367.5 u + 257.25 u^2), 5/7 < u < 6/7}, {5.25, u == 6/7}, {33.8811 v^2 , u > 1/7}}, -1380.75 + 3160.5 u - 1800.75 u^2] When you set shared ...


3

seems to work: expr /. Times[xx_?(! FreeQ[#, x] &) , p_plusd, rest___] :> Times[xx /. x -> 1, p, rest] and terms like: 2 Log[(sa1 (-2 + x))/(-mgl^2 + sa1 (-2 + x))] plusd[1/(1 - x)] and Log[2 + mgl^2/sa1 - x] plusd[-(2/(-1 + x))] were reduced to 2 Log[-(sa1/(-mgl^2 - sa1))] plusd[1/(1 - x)] and Log[1 + mgl^2/sa1] plusd[-(2/(-1 + x))] ...


12

Original question As noted in the comments the use of Dispatch is the easiest way to make this replacement operation much faster. However taking this as an opportunity to explore other optimizations here are some examples for you to consider: (dsp = Dispatch[soln]) // RepeatedTiming // First 0.0030 Total[vars] /. dsp // RepeatedTiming {0.0038, ...


11

Update: I think I've got it. I found a token that does the replacement without bringing up a dialog. The values from the last use of the Find and Replace dialog will be used. The command is: FrontEndExecute @ FrontEndToken[nb, "ReplaceAll"] where nb is the target Notebook object. To preset the Find and Replace fields one can modify the FindSettings ...


1

ReplaceAll works on "the structure", not the "pretty printed" form. FullForm[I] gives Complex[0, 1] and I /. Complex[0, 1] -> Complex[0, -1] gives -I


3

Look at LK4[{a, b, c, d}, I, 0, 0, 0, 0] What has happened is that the a in the argument {a, b, c, d} has been replaced by {1, 2, 3, 4} in the Sum[..., {a, 1, 4}] code in the definition of LK4. If you change the definition of LK4 to use a different iterator, you get consistent results: LK4[coeff_, tau_, xi1_, xi2_, x_, y_] := ...


1

For Version 9.0.1.0 (Windows 8 64-bit), this seems to be a good use case for the function Internal`FromCoefficientList: bifclF = Block[{Power = f[#2] &, x = f[1]}, Internal`FromCoefficientList[#, x]] & Examples: Using @bobthechemist's examples test1 = 1 + x + x^2 + x^4; test2 = 2 + x - x^2 + x^4; test3 = -2 - x + x^2 - x^4; test4 = -2 - x - x^2 - ...


4

From the first line in the details section in the documentation for ReplaceAll: ReplaceAll looks at each part of expr, tries all the rules on it, and then goes on to the next part of expr. The first rule that applies to a particular part is used; no further rules are tried on that part, or on any of its subparts." Basically what's happening is since ...


3

Here is what might be considered a classic example of the difference. Suppose I have a list containing a number of xs and maybe some other elements, and I want to replace the xs with random integers in some range, but I want new random draw for each replacement. SeedRandom[42]; {x, y, x, x, y} /. x -> RandomInteger[9] {6, y, 6, 6, y} doesn't work ...


5

Because sometimes I is not I... Hold[I] // FullForm I -> a // FullForm Results in: Hold[\[ImaginaryI]] Rule[Complex[0, 1], a] You can see that in the first expression I is held and remains the same. However, in the second expression I is evaluated (since Rule does not have any Attributes to hold its arguments). I gets evaluated into a Complex ...



Top 50 recent answers are included