Tag Info

Hot answers tagged

4

Since, Attributes[Function] {HoldAll, Protected} Use Evaluate f = Function[{x}, Evaluate[(1 - # &)@*(1 - # &)@x]] Function[{x}, x] f@x x


4

Use ComplexExpand expr = Abs[x + I y] + Sin[Abs[c + I (d + e)]]; expr // ComplexExpand Sqrt[x^2 + y^2] + Sin[Sqrt[c^2 + (d + e)^2]]


4

Simplifications work only if you avoid branch cuts of the inverse function. Here I do that for the ArcTan function, but using the relation that I think you meant to prove (I may have guessed wrong, of course): FullSimplify[ ArcTan[-I (Exp[2 I x] - 1)/(Exp[2 I x] + 1)], -Pi/2 < x < Pi/2] (* ==> x *) For the second part of the question, how to ...


3

Everything is as it should be. In the first instance, you want a separate rule for each element of the list. For that, you can use Thread: Subscript[Ε, si] = {Ex, Ey, Ez}; Subscript[B, si] = {Bx, By, Bz}; Subscript[S, si] = 1/Subscript[μ, 0] (Subscript[Ε, si]* Subscript[B, si]); Subscript[S, si] /. Thread[Subscript[B, si] -> Subscript[B, si]/c] ...


3

eqn = x/y + x/y^2 + x/y^3 + x/y^4 == 4/x; Numerator[Together[eqn /. Equal -> Subtract]] == 0 x^2+x^2 y+x^2 y^2+x^2 y^3-4 y^4==0 %// TeXForm $x^2 y^3+x^2 y^2+x^2 y+x^2-4 y^4=0$ Or, flttnF = Numerator[Together[# /. Equal -> Subtract]] == 0 &; flttnF@eqn (* same result *)


3

In recent versions of Mathematica you should see something like this: RandomInteger[99, {500, 50}] Or like this (version 7): Clicking show all or Show Full Output should do just that. Be aware that if the expression is large this can hang the Front End or consume all your RAM. Within the preferences you should also have something like this (the ...


3

For performance fiends: I had an application that had this very need for some huge sets of long integer strings. kguler's solution is certainly the canonical way, and quite quick, as is Felix's version (I was actually surprised on that one). eldo's solution is probably what most would come up with, but in performance-intensive scenarios the StringSplit is ...


3

Generally speaking, If is for programming and Piecewise is for function construction. While the distinction is somewhat artificial, the significant difference is that Piecewise, although having the attribute HoldAll, evaluates its arguments. The effective difference can been seen by evaluating q1[t] with the OP's definition of k[v] and this one: k[v_] := ...


2

You can also use a combination of StringSplit, SyntaxQ and Pick: str = "{Aaaa -> a, Bbbb- > b, Cccc -> , Ddddd -> c, Eeeee -> , Fffff -> e}"; str2 = Pick[#, SyntaxQ /@ #] &@StringSplit[str, "," | "{" | "}"] (* {"Aaaa -> a", " Ddddd -> c", " Fffff -> e"} *) ToExpression@str2 (* {Aaaa -> a, Ddddd -> c, Fffff -> e} *) ...


2

You can use StringCases. str = "{Aaaa -> a, Bbbb -> b, Cccc -> , Ddddd -> c, Eeeee -> , Fffff -> e}"; ToExpression@StringCases[str, WordCharacter .. ~~ " -> " ~~ WordCharacter ..] {Aaaa -> a, Bbbb -> b, Ddddd -> c, Fffff -> e}


2

FromDigits /@ StringSplit["1 2 3 4 5 6"] ToExpression@StringSplit["1 2 3 4 5 6"] StringCases["1 2 3 4 5 6", ns : NumberString :> FromDigits[ns]] ToExpression@StringCases["1 2 3 4 5 6", NumberString] all give (* {1, 2, 3, 4, 5, 6} *)


2

res = ToExpression@StringSplit["1 2 3 4 5 6", " "] {1, 2, 3, 4, 5, 6} Head /@ res {Integer, Integer, Integer, Integer, Integer, Integer}


2

Flatten[ImportString["1 2 3 4 5 6", "Table"]] {1,2,3,4,5,6} Head /@ % {Integer, Integer, Integer, Integer, Integer, Integer}


2

You can start by simply creating a function that tests, whether a string is a list of rules or not isTransformable[str_String] := SyntaxQ[str] && MatchQ[MakeExpression[str], HoldComplete[{_Rule ..}]]; isTransformable[___] := False; Note that this function does much more that search for a "->" inside a string. First, it tests, whether the ...


2

Because you made a mistake when using double angle identity. In your equations, I got(2 Sin[θ/2]) == (1 - Cos[θ]), where it should be (2 Sin[θ/2]^2) == (1 - Cos[θ]) Assuming[μ > 0 && g > 0 && ℏ > 0 && m > 0 && k > 0, Integrate[(4 μ^2 g^2)/(ℏ^4 (m^2 + 4 k^2 Sin[θ/2]^2)^2) Sin[θ], {θ, 0, π}, {ϕ, 0, 2 π}]] // ...


2

Use ComplexExpand to tell M all symbols are real ComplexExpand[Im[(20 + 140 I)*Lg + (7 + 140 I)*Ls], {Ls > 0, Lg > 0}] See help on ComplexExpand. Ps. This question has been asked many times before and is duplicate. Will be closed.


2

Patterned assumptions seem to need to match the ConditionalExpression's condition exactly to work out for some cases. The ∈ Reals-assumptions do work as you gave them, while the inequality Subscript[s,_]>0 does not, but observe the different behavior of Subscript[s,_]>=0: Evaluating without any assumptions first: f = 1/\[Sqrt](2 \[Pi] Subscript[s, ...


2

You main problem here is that a SymmetrizedArray is not an expression once you have constructed it. It is an atom, a raw object that (although it looks otherwise) cannot be decomposed into smaller expressions AA = SymmetrizedArray[{{1, 2} -> (a^2 - b^2)^3, {1, 3} -> ((a - b) (a + b))^3, {2, 3} -> x}, {3, 3}, Antisymmetric[{1, 2}]]; AtomQ[AA] ...


2

I'm guessing you are looking for the list of replacements that need to be made going down to level 0 instead of just showing the level 0 results. Are you looking for something like this? assignments[d] = a + b; assignments[e] = b c; assignments[f] = d e; assignments[x_] := x; FixedPointList[Map[assignments, #, {-1}] &, {f}][[;; -2, 1]] {f, d e, b ...


2

Maybe I missed the point, but if you just copy and paste your expressions (and insert spaces to give multiplication) you get: d = a + b; e = b c; f = d e which gives you b (a + b) c, which is equivalent to your given f. Is this all you were asking?


2

expr = Abs[x + I y] + Sin[Abs[c + I (d + e)]]; expr /. Abs[a_ + I*b_] -> Sqrt[a^2 + b^2] (* Sqrt[x^2 + y^2] + Sin[Sqrt[c^2 + (d + e)^2]] *) Have fun!


2

You may consider this, rl= (a_. Sum[b_. Subscript[x_, i_], {i_, i0_: 1, n_}]) :> Sum[(a b) Subscript[x, i], {i, i0, n}]; exp = Sum[2/9 Subscript[x, i], {i, 1, n}] + 2 Sum[1/9 Subscript[x, i], {i, 1, n}]; Apply transformation rule repeatedly: exp //. rl Collecting more than two sums: exp1 = 1 Sum[3/9 Subscript[x, i], {i, 1, n}] + 3 ...


1

Use a replacement rule rule = (a1_. * Sum[c1_. Subscript[x_, i_], {i_, i0_: 1, n_}] + a2_. * Sum[c2_. Subscript[x_, i_], {i_, i0_: 1, n_}]) :> Sum[(a1*c1 + a2*c2) Subscript[x, i], {i, i0, n}]; expr = Sum[2/9 Subscript[x, i], {i, 1, n}] + 2 Sum[1/9 Subscript[x, i], {i, 1, n}]; expr /. rule Sum[(4*Subscript[x, i])/9, {i, 1, n}]


1

The problem here is with FullSimplify, not your definition. (First I'll rewrite your definition to be a little more standard.) myArcTan[c_, s_] := Pi + ArcTan[-c, -s] Just because Mathematica fails to Simplify this expression myArcTan[Cos[x], Sin[x]] to x doesn't mean that they're not equal: Plot[myArcTan[Cos[x], Sin[x]], {x, 0, 2 Pi}] In fact, ...


1

Not sure if I understand you correctly but you can define your own function as follows: f[0, x_] := Sign[x] Pi/2 f[x_, y_] := ArcTan[x, y] f[Cos[x_], Sin[x_]] := x FullSimplify[f[Cos[x], Sin[x]]] (*x*) Based on your comments, I can suggest for you this method: MyArcTan[x_, y_] := ArcTan[-x, -y] + Pi; MyArcTan[r_.*Cos[x_], r_.*Sin[x_]] := x; Assuming[0 ...


1

The document never promises that pattern-matching is supported inside Assumptions. (Though in some cases it does seem to be!) So the only stable way I can think of is as following: Subscript[g, i_][x_] := ($Assumptions = Union[$Assumptions~Join~ {{Subscript[m, i], Subscript[s, i]} ∈ Reals, Subscript[s, i] > 0}]; Exp[-((x - Subscript[m, ...


1

This might be what you want: myfullsimplify[expr_, assum_] := Module[ {pat, tmp, seq}, pat = FirstCase[Level[assum, Infinity], p[_]] /. p[x_] -> x; tmp = FirstCase[Level[expr, Infinity], pat]; seq = {expr, assum} /. {pat -> #, p[_] -> #}; FullSimplify @@ seq /. # -> tmp ] It's used as follows: myfullsimplify[entry[1, 2, 3] < 0, ...


1

I don't quite understand your code, especially the key_/;key->val_ part, but the following code shall do your work: ToExpression@str //. key_String /; StringMatchQ[key, ___ ~~ "->" ~~ ___] :> ToExpression[key]


1

Or the StringReplace version: In[3]:= StringReplace[str, WordCharacter .. ~~ " -> ," -> ""] Out[3]= "{Aaaa -> a, Bbbb -> b, Ddddd -> c, Fffff -> e}" In[4]:= ToExpression@% Out[4]= {Aaaa -> a, Bbbb -> b, Ddddd -> c, Fffff -> e}


1

ToExpression["{" <> StringReplace["1 2 3 4 5 6", " " -> ","] <> "}"]



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