Tag Info

New answers tagged

5

Very simply Power[__] evaluates to __ and __ matches any expression: expr = {x, Cos[Exp[x]], x^a}; Power[__] Cases[expr, __, -1] __ {x, E, x, E^x, Cos[E^x], x, a, x^a}


3

_^_ instead of Power[__] may give you the result you desire. The issue is that all expressions strictly match themselves to the first power! MatchQ[x, Power[__]] True MatchQ[x, Power[_, 1]] True MatchQ[x, _^_] False Considering you example... expr = {x, Cos[Exp[x]], x^a} Cases[expr, _^_, -1] // InputForm {E^x, x^a}


4

The other commentators are correct that Except does only allow single-letter strings. Note that you could also use RegularExpression here: StringReplace["xxxyxz", RegularExpression["x[^y]"] -> "ww"]


1

Answer the last question first. In a word, it's a simple mistake: Cases[integrands[[-1]], Derivative[_], Infinity, Heads -> True] // Sort // Last Derivative[10] As you see, the highest order of derivative in integrands isn't tmax which equals 3. Another small mistake that leads to some warnings but doesn't influence the result is that ...


1

I didn't go deep to the possible repetitive calculation of f[x] and its derivative (actually I doubt if they are the bottleneck of speed, due to my… intuition), but your code got a 1.25X speed up in my computer with the Together in your integrand[t] being taken away: gauMix[means_, vars_] := Total[Apply[(1/(Sqrt[2*Pi*#2]*Length[vars]))* E^-(((x - ...


10

It is my impression (based solely on the examples in the documentation) that in the context of strings Except only allows single-letter strings. Compare StringMatchQ["q", Except["p"]] True with StringMatchQ["qq", Except["pp"]] Therefore, you generally need to rephrase your string patterns using the StringPattern and RegularExpression syntax. ...


0

If I understood your question, I assumed you are asking what determines the order of execution of patterns. If we assume Mathematica a black box with an input and and output, we can consider the input the domain of an "ordering function" and the output its range. An injective function is a one to one map so that each element in the domain maps to a single ...


0

As a relative newbie still just trying to learn how to use patterns, your notion of "specificity" seems unclear to me, perhaps because I am in way over my head already. Nevertheless, uneducated, but earnest fools go where wiser men dare not tread. According to the documentation ...


0

Short Answer Change the variables in sol into Head /@ variables. Long Answer Before answering your question, I'd like to suggest you to try to simplify your code sample as much as possible before posting it here so your question will draw more attention. To summarize, something seems to be "wrong" when you try to plot the derivative of the output of the ...


0

Changing Rule to RuleDelayed r = z[(x + 2)^2]; r /. z[a_] :> Expand[a] (* 4 + 4 x + x^2 *) r /. z[a_] :> Integrate[a, {x, 0, 10}] (* 1720/30 *) gives the desired output. Alternatively, you can use Rule to replace the Head z with the desired function: r = z[(x + 2)^2]; r /. z -> Expand (* 4 + 4 x + x^2 *) r /. z -> (Integrate[#, {x, 0, 10}] ...


2

Plot[D[variables /. sol, t] /. t -> u, {u, 0, 10}, Evaluated -> True]


0

Works for me if I change your plot line to Plot[variables /. sol, {t, 0, 10}]


5

Since we can not see the source code of Mathematica, we don't know the detailed algorithm Mathematica use to do string pattern searching. But in most other languages, they use KMP algorithm to do explicit string matching. KMP is in fact a very compact design of the DFA pattern matching algorithm. You can find a comparison here. You can see that the ...


3

Use this: f = Compile[{{lst, _Real, 2}, {val, _Real, 1}}, First@First@Position[lst, val]]; f[samplelist, {1, 3}] (*3*)



Top 50 recent answers are included