Tag Info

New answers tagged

1

ToExpression[ "{a-> POR, b-> D610, c-> 0, d-> \"300/7\", e -> \"1/400\"}" ] /. s_String :> Defer @ ToExpression[s] {a -> POR, b -> D610, c -> 0, d -> ToExpression["300/7"], e -> ToExpression["1/400"]} response to comment: ToExpression[ "{a-> POR, b-> D610, c-> 0, d-> \"300/7\", e -> ...


2

Your equation is easier to handle if it put into an equivalent form. eq1 = Sqrt[l1] + Sqrt[t1] + Sqrt[w1] == d; It is also to convenient to write the rules as r1 = {l1 -> (pw^2 w1)/((1 + a e1)^2 w^2)}; r2 = {t1 -> (pw^2 w1)/((1 + a e1)^2 r^2)}; and substitute u^2 for w1 getting a new equation eq2 = eq1 /. Join[r1, r2] /. w1 -> u^2 ...


0

Try also this: as = <|"Aa" -> "1/2", "Av" -> "2/5", "Ca" -> "3/4", "Bx" -> "3/7", "Ce" -> "4/9"|>; ks = KeySelect[as, Characters[#][[1]] == "A" || Characters[#][[2]] == "a" &]; op = Map[ToExpression, ks, 2]; Merge[{Association[Complement[Normal[as], Normal[ks]]], op}, Total] yielding (* <|"Bx" -> "3/7", ...


1

cr = CoefficientRules[myExpr, {Delta, phi}] cr /. HoldPattern@(a_ -> b_) :> f @@ a -> b FromCoefficientRules[cr /. HoldPattern@(a_ -> b_) :> a -> f @@ a, {Delta, phi}] (* f[0, 0] + Delta f[1, 0] + Delta phi f[1, 1] *)


3

A variation on the theme: test = {Aa -> "1/2", Av -> "2/5", Bx -> "3/7", Ce -> "4/9"}; test /. (key_ /; StringMatchQ[ToString[key], ___ ~~ "a" | "A" ~~ ___] -> val_) :> (key -> ToExpression[val]) (*{Aa -> 1/2, Av -> 2/5, Bx -> "3/7", Ce -> "4/9"}*)


6

I would use something like this: Clear[f]; f[key_ -> val_] := key -> If[ StringMatchQ[ToString@key, ___ ~~ "A" | "a" ~~ ___], q@val, val] then f /@ {Aa->1/2, Av->2/5, Bx->3/7, Ce->4/9} (* {Aa -> q[1/2], Av -> q[2/5], Bx -> 3/7, Ce -> 4/9} *) If you have v10, and your data is in an Association, you use AssociationMap, ...


1

As a place to start I suggest TransformationFunctions: FullSimplify[expr1, TransformationFunctions -> {Automatic, schId, sortarg}] 0 This works even if both sortarg and schId are defined with /. rather than //.. For more manual application consider MapAt. Also familiarize yourself with levelspec.


1

a = TrigToExp[3 + 4 Cos[u] + Cos[2 u]] 3 + 2/E^(I*u) + 2*E^(I*u) + 1/2/E^(2*I*u) + (1/2)*E^(2*I*u) b = a /. u -> Log[z]/I // Simplify (1 + z)^4/(2*z^2) (b /. z -> E^(I*u)) == a // Simplify True


1

StringReplace just searched from left to right and replaced all the zero-length string for once. Here is a way to visualize the process: i = 0; StringReplace[{"90", "", "20"}, "" :> ToString[Style["0", {Orange, 15 + 5 i++}], StandardForm]] The inserted zero is dyed into orange and becomes bigger every time the replacing rule is applied so you can ...


8

As others have indicated this result is not surprising at all. What you actually need is not StringReplace but ReplaceAll (/.): {"90", "", "20"} /. "" -> "0" {"90", "0", "20"}


7

The illustrated behavior seems reasonable to me, even if it may not seem "natural." For position or replacement a given pattern should match when it appears between any two sequences of characters, or it is at the beginning and end of a string. A zero-length string effectively is between every pair of characters. Why should it not match? To keep it from ...


5

That is a rather slippery replacement, "Find nothing and replace it with something" Try telling the replacement that there nothing between the beginning and end StringReplace[{"90", "", "20"}, {StartOfString ~~ "" ~~ EndOfString -> "0"}]


1

Assuming that the problem only lies with c1, c2 and the Table, and ignoring any error message, if I use a self-constructed minimal working example c1 = "I'm GLOBAL"; vesselness[im_, Sigma_] := Module[{k1 = BAR1, k2 = BAR2, c1, c2 = c1}, {im, k1, k2, c2} /. c1 -> "I'm local" ]; vesselness[subIm, ref] the result is {subIm, BAR1, BAR2, "I'm ...


5

Here's the problem in a nutshell: Module[{c1, c2 = foo[c1]}, c2 /. c1 -> value] (* ==> foo[c1] *) The point is, Module replaces c1 by a local variable in its body, but not in later assignments in the variable list. You can see what happens by just looking at the variables: Module[{c1, c2 = foo[c1]}, {c1,c2}] (* ==> {c1$184, foo[c1]} *) You ...


0

Clear[g] g[k_] = 1 + 2 Sum[1/(1 + (2 n)^2), {n, 1, k}] // FullSimplify (1/2)(PiCoth[Pi/2] - IHarmonicNumber[-(I/2) + k] + IHarmonicNumber[I/2 + k]) For integer arguments you can use FunctionExpand to get an exact rational result with very large numerator and denominator. Use N to convert to approximate real result. Table[{n, g[n] ...


1

Without the 1. +, your expression evaluates to: 1/2 I (PolyGamma[0, 1 - I/2] - PolyGamma[0, 1 + I/2] - PolyGamma[0, 51 - I/2] + PolyGamma[0, 51 + I/2]) When you add 1., although the imaginary parts cancel, the answer remains a complex number. The reason you get a real number when you evaluate g[50] is that the sum doesn't use the general form, but ...


2

rewriteF[e_, v_, cf_] := If[cf[Coefficient[#[[2]], v]], Solve[Equal @@ #, v][[1, 1]], #] & /@ e rewriteF[toylist, b, # > 10^5 &] (* {b -> (a - 2 c)/1000000000000, d -> -0.5` b + e/100000000000, f -> 2 g} *) rewriteF[toylist, g, Positive] (* {a -> 1000000000000 b + 2 c, d -> -0.5` b + e/100000000000, g ...


5

Brute force: toylist /. Rule[lhs_, rhs_] :> With[{ coeff = Coefficient[rhs, Variables[rhs]] }, Solve[lhs == rhs, #][[1, 1]] &[ Last[Variables[rhs][[Ordering[coeff]]]] ] /; Max[coeff] > 10^5 ] {b->(a-2 c)/1000000000000,d->-0.5 b+e/100000000000,f->2 g} You can reverse condition: /; Min[coeff] < 10^-5 ...


0

The second substitution is easier to code than the first: expr = Sqrt[2 + k^4 + Sqrt[k^2 (8 + k^6)]] - Sqrt[2 + k^4 - Sqrt[k^2 (8 + k^6)]]; Assuming[0 <= k <= 1, expr /. {Sqrt[a_ + Sqrt[b_]] + (sgn_: 1) Sqrt[a_ - Sqrt[b_]] /; Simplify[a >= 0 && b >= 0 && a^2 - b >= 0 && Abs[sgn] == 1] :> Sqrt[2] Sqrt[a ...


3

When you define a function f, you are (a) applying Set or SetDelayed to a pattern, (b) creating a rule, (c) associating the rule with a symbol (f), and (d) storing that in DownValues (usually). FullForm[Hold[f[x_] := x^2]] (* Hold[SetDelayed[f[Pattern[x, Blank[]]], Power[x, 2]]] *) f[x_] := x^2 DownValues@f (* {HoldPattern[f[x_]] :> x^2} *) First ...



Top 50 recent answers are included