New answers tagged

0

If you want coefficients of your expression, you'd better use Coefficient. Here are the functions for which you want to determine the coefficients: functions = Cases[{exp1, exp2, exp3}, Exp[x_]|Sin[x_]|Cos[x_], Infinity] // Union $\{ e^{-\frac{t}{x^2+y^2}}\,, \, \cos\Big[\frac{2\pi t}{T}\Big]\,,\, \sin\Big[\frac{2\pi t}{T}\Big] \}$ Then the ...


3

Try learning to type with the synatx is better than using the maths tools, Define u[x_, y_] := 2 x*y^3 v[x_, y_] := 2 x^2*y^2 Then, epislonX = D[u[x, y], x] 2 y^3 and epislony = D[v[x, y], y] 4 x^2 y


2

Explanation The problem is that pattern matching in Mathematica is purely structural - this means that e.g. the pattern a_ + b_ * f[_] will not match 3 (even though you could set b to 0 from a mathematical point of view): split = a_ + b_*f[_] :> {a, b}; 1 + 3 f[x] /. split 3 /. split (* {1, 3} *) (* 3 *) To circumvent this, we can use Optional to ...


0

Here is some code which I think should do what you are after: ClearAll@scoreResults; scoreResults[a_ /; NumericQ[a[0]]] := Module[{temp, i}, temp = 0; For[i = 0, i < 2, i++, temp = temp + a[i]; If[a[i] > 300, temp = temp + 100000 ] ]; temp ] NMinimize[{scoreResults[a], {a[0] > 222, a[1] > 333}}, {a[0], a[1]}] note ...


2

This is entirely equivalent to Bob's answer: x + x^2 /. x^m_. :> Moment[BinomialDistribution[k, p], m] 2 k p - (1 - k) k p^2


6

If you are calculating the expectation of an expression, use Expectation or other built-in statistics functions rather than replacements which can be error-prone (which is why you ended up asking the question). expr = x + x^2; Expectation[expr, x \[Distributed] BinomialDistribution[k, p]] // Simplify (* k p (2 + (-1 + k) p) *) Alternatively, using ...


14

Give the replacement rules in a list: expr /. {x^2 -> k p + k (k - 1) p^2, x -> k p} 2 k p + (-1 + k) k p^2


4

This is the purpose of Formal Symbols. They are special symbols that can not be set to a value so that they will not clash with variables in your code. For formal lowercase x you enter Esc$xEsc. foo[a_] := Probability[\[FormalX] > 0, \[FormalX] \[Distributed] NormalDistribution[a, 1]] Which looks like the image below in a notebook. With this the ...


8

One way around this could be to make local x inside your module. Like this foo[a_] := Module[{x}, Probability[x > 0, x \[Distributed] NormalDistribution[a, 1]]] And now you can do foo[-1] // N And foo[x] /. x -> -1


0

I am a bit confused but if you use your definition of Riccil1 and make the replacement without defining m[u_] it would look like the following. First I remove the power to the 1/4 on each side and multiple both sides by negative one. Ricci11 /. a12[u]^2 - a11[u] a22[u] -> -Det[m[u]] Hope this helps.


3

ClearAll[x, k, z] With[{ k = (z[1, 3] z[2, 4])/(z[1, 2] z[2, 3] z[3, 4] z[4, 1]), x = (z[1, 2] z[3, 4])/(z[1, 3] z[2, 4]) }, k x ]/x


2

Perhaps this will handle your first problem. Simplify[{4*i*sigma*t1-i*B,-4*i*sigma*t1- -i*B, 8*i*sigma*t1-2*i*B,-8*i*sigma*t1--2*i*B,etc}, 4*i*sigma*t1-i*B==i*gamma] instantly returns {gamma*i, -(gamma*i), 2*gamma*i, -2*gamma*i, etc} Carefully read the documentation for Simplify and in particular how you can add an extra argument specifying assumptions ...


3

Just include the patterns you want to avoid in your replacement rule: ReplaceAll[ {z + Re[a], Hold[1 + Re[b]], Function[z, Abs[Re[c]]]}, { h:(_Hold | _Function) :> h, Re[x_] :> (x+Conjugate[x])/2 } ] {z + 1/2 (a + Conjugate[a]), Hold[1 + Re[b]], Function[z, Abs[Re[c]]]}


Top 50 recent answers are included