Hot answers tagged

11

My offering: And @@ Or @@@ Outer[Equal, {x, y, z, m}, {2, 3, 4}]


7

To be very explicit and related to the situation in your question, consider this simple function f and the different fs that all might be ways to compute the derivative at a first glance. ClearAll[f, fs, fs2, fs3, fs4]; f[x_] := x^2; fs[x_] := D[f[x], x]; fs2[x_] := f'[x]; fs3[x_] = D[f[x], x]; fs4[x_] := Block[{t}, D[f[t], t] /. t -> x]; Let's check ...


6

It seems that it will align the column to the first character of the string you put there. So it's an undocumented extension to: "c" - align on the character "c" Column[{ "OffOutputasodas", "OutputOffo", "adssoadasOffOutput" }, "Output" ] Column[{ "OffOutputasodas", "oOutputOffo", "adssoadasOffOutput" }, "output" ]


5

You could do : Fpmat = Switch[Sign[Im[{EEV1,EEV2,EEV3,EEV4}]], {1, 1, _, _}, Transpose[{EVEC1, EVEC2}], {1, -1, 1, _}, Transpose[{EVEC1, EVEC3}], {1, -1, -1, 1}, Transpose[{EVEC1, EVEC4}], {-1, 1, 1, _}, Transpose[{EVEC2, EVEC3}], {-1, 1, -1, 1}, Transpose[{EVEC2, EVEC4}], {-1, -1, 1, 1}, Transpose[{EVEC3, ...


4

a1 = NDSolve[{y1''[x] - 0.1 y1[x]^0.25 == 0, y1'[0] == 0, y1[1] == 1}, y1, {x, 0, 1}] Plot[y1[x] /. a1, {x, 0, 1}, GridLines -> Automatic] Mathematica 10.4.1 on Windows 10 (64 bit)


3

I think you are looking for something like this: ordered = {#[[1]], StringRiffle@sort[StringSplit@#[[2]], weights]} & /@ needsreorder Export["ordered50parts.csv", ordered] (*{{"PARTNUM", "DESC"}, {"DUK175189", "Blower Hose 14"}, {"ROU4060436", "Halogen Lamp 100 120 Volt Watt"}} *)


3

The number of different actions that can result from the various conditions is much smaller than the number of conditions. What you have to do is collect all the conditions leading to identical actions, and then combine these conditions with Or (written usually as ||). That's all there is to it. I'll leave the typing to you.


3

In version 10, you can use this simpler syntax without Thread: Solve[x+2y+z+m==14&&2<=var<=3,var,Integers] {{x->2,y->3,z->3,m->3},{x->3,y->3,z->2,m->3},{x->3,y->3,z->3,m->2}}


3

This is one aspect of a classic problem: Plot is HoldAll. So, moreProp is not being evaluated. I think the most effective way to work around this is to use With (cf. this question) to inject the values into Plot, e.g. newPlot[func_, range_, prop___] := With[{mp = moreProp}, Plot[func, range, prop, mp]] Then, it works: Alternatively, you can use ...


2

How about defining: f[{ 1, 1, _, _}] := Transpose[{EVEC1, EVEC2}] f[{-1, 1, 1, _}] := Transpose[{EVEC2, EVEC3}] f[{ 1, -1, 1, _}] := Transpose[{EVEC1, EVEC3}] f[{-1, -1, 1, 1}] := Transpose[{EVEC3, EVEC4}]; f[{ 1, -1, -1, 1}] := Transpose[{EVEC1, EVEC4}]; f[{-1, 1, -1, 1}] := Transpose[{EVEC2, EVEC4}]; f[_] := Print["choose another value of ...


2

Braces [], brackets {}, and parenthesis () all have different meanings in mathematica. Sorry for the post. I will read the documentation and tutorials more completely.


2

Wrap your Monitor call in a Function object endowed with a holding attribute: Table[Pause[n/10], {n, 10}] // Function[{input}, Monitor[input, n], HoldAll] This will work as though you had wrapped Monitor around your Table.


2

You can use Unevaluated Unevaluated@Table[Pause[n/10], {n, 5}] // Monitor[#, n] & The neater way will be to use the infix version as suggested by wxffles in the comments, but your question specifically asked for postfix so... For completeness, here it is Table[Pause[n/10], {n, 5}] ~Monitor~ n


2

Adding links to comment by MarcoB Note the Attributes of RegionPlot Attributes[RegionPlot] (* {HoldAll, Protected, ReadProtected} *) Since RegionPlot and other plot functions have attribute HoldAll you need to use Evaluate a = {x^2 < y^3 + 1, y^2 < x^3 + 1}; RegionPlot[Evaluate[a], {x, -2, 5}, {y, -2, 5}]


2

A PDF is not a distribution. To convert a PDF to its associated distribution use ProbabilityDistribution Clear[λ, pb, Ps, μ] f[h_] := 1/Gamma[m]*(m/P)^m*h^(m - 1)*Exp[-(m*h)/P]; m = 1; P = 1; α = 4; δ = 2/α; int = Assuming[{A > 0, r > 0, λ > 0}, Integrate[(1 - Exp[-x*h*r^(-1/δ)])*pb*λ*π, {r, A, Infinity}, GenerateConditions -> False]] ...


2

This is an extended comment. f[h] as defined while clearly a probability density function is not of the type of function that Expectation expects. Consider the difference between the two functions f and g below: f[h_] := 1/Gamma[m]*(m/P)^m*h^(m - 1)*Exp[-(m*h)/P] (* Head *) Head[f] (* Symbol *) (* PDF *) f[h] (* (E^(-((h m)/P)) h^(-1 + m) ...


2

I think that value injection using With will work for you. Let's first define the sample g value you want: g = 1 + x^2 Now we define myfunc injecting the current definition of g inside its definition: Clear[myfunc] With[{g = g}, myfunc[f_] := Simplify[f/g]] Now let's change the value of g and check whether the definition of myfunc is affected: g = ...


1

Define the integrand with the measure as integrand = c*Exp[-m*x^2/ω^m]*1/(Sqrt[2*π]*λ*ω)*Exp[-(Log[B] - μ)^2/(2*λ^2)] Dt[B, Constants -> {λ, m, x, μ, ω}]; where we use Dt[t] to represent the measure, which we will transform using the substitution: subs = Assuming[{μ > 0, λ > 0, B > 0, t ∈ Reals}, First@Solve[t == (Log[B] - μ)/(Sqrt[2] λ), B, ...


1

I think you almost did right, but you need to give the distribution rather than the PDF of a distribution when evaluating the expectation. For example: f[x_] := Sqrt[2]/Pi/(1 + x^4) distX = ProbabilityDistribution[f[x], {x, -Infinity, Infinity}]; distY = TransformedDistribution[X^2, X \[Distributed] distX]; distI = TransformedDistribution[2 Y + 1, Y ...


1

Maybe something like this? g = 1 + x^2 Unprotect[saveg] saveg = g; myfunc[f_] := Simplify[(f/saveg)] Protect[saveg]


1

See ReplaceAll and What are the most common pitfalls awaiting new users?. Say you want to find a root, you would code something like rule = FindRoot[x^3 - Tanh[x], {x, 1.0, 1.2}] and get as result: {x -> 0.893395} Next step ist (as proposed by @Alexei Boulbitch) expr/.rules applies a rule or list of rules in an attempt to transform each ...


1

A set solution. cond = {{x}, {y}, {z}, {m}} ∈ Interval[{2, 4}] && {x, y, z, m} ∈ Integers Set x, y, z, and m to be Integers on the Interval 2 to 4. We can use cond to be certain it is defined as expected. Solve[x + y + z + m == 8 && cond, {x, y, z, m}] (* {{x -> 2, y -> 2, z -> 2, m -> 2}} *) This gives the expected result. ...



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