Hot answers tagged

11

You can rewrite your idea using If as follows: If[MemberQ[elList, #], 1., 1.13] & /@ els {1.13, 1., 1., 1.13, 1.} However you may find on larger problems that repetitive use of MemberQ is not as fast as you would like, so consider a hash table in the form of an Association, or if using an older version of Mathematica a Dispatch table. Create a ...


5

Albert Retey has demonstrated in a similar situation that you can use "EventLocator" to detect an event in NDSolve. For example: eqn = {\!\( \*SubscriptBox[\(∂\), \(t\)]\(u[t, x]\)\) == 1/100 \!\( \*SubscriptBox[\(∂\), \(x, x\)]\(u[t, x]\)\) - u[t, x] \!\( \*SubscriptBox[\(∂\), \(x\)]\(u[t, x]\)\), u[0, x] == Sin[2 π x], u[t, 0] == u[t, 1]}; ...


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)


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

I learned a lot from WReach's and Leonid's answers and I'd like to make a small contribution: It seems worth emphasizing that the primary intention of the list-valued second argument of Flatten is merely to flatten certain levels of lists (as WReach mentions in his List Flattening section). Using Flatten as a ragged Transpose seems like a side-effect of ...


2

This may be an answer. Your code is ill-formed. It does not conform to Mathematica syntax. I have rewritten it to be valid and to better correspond to your pseudocode. There is no guarantee that it actually corresponds to the process you want to simulate, but at least it prints output and terminates. I hope it will help you to move forward. With[{n = 2}, ...


2

Use Mapping multiple parameters of a function to specific values and supply it with the following version of parameters. parameters=Flatten[Table[{a, 1/bInverted}, {a, 1/2, 5, 1/2}, {bInverted, 2, 5}], 1] Update Let's redefine myfunction to be a function of a, b and x. myfunction[a_, b_, x_] := (b/a)*((a/x)^(b + 1)) Now when you generate parameters ...


2

A method is to write a message handler, like in this answer. The handler is passed an argument of the form Hold[Message[...], boolean] where the boolean tells the handler if the message is to be displayed, or not. Since you are looking to capture the info passed to NDSolve::ndsz, I would write the handler like Clear[messageHandler, vals]; vals = {}; ...


1

Activate@Replace[Inactive[f][3],3->1, Infinity] 1 or Replace[Hold@f[3], 3 -> 1, Infinity] // ReleaseHold 1


1

ps = Accumulate[(1 + #)^2 (-1)^# & /@ Range[0, 9]] (* or ps = Accumulate[Range[#]^2 (-1)^Range[0, # - 1]] *) {1, -3, 6, -10, 15, -21, 28, -36, 45, -55} sps = Accumulate[ps] {1, -2, 4, -6, 9, -12, 16, -20, 25, -30} means = MapIndexed[#/First[#2] &, sps] {1, -1, 4/3, -(3/2), 9/5, -2, 16/7, -(5/2), 25/9, -3} Combine in single ...


1

If speed is not you concern, may be this can be worth a try common = Intersection[elList, els]; u = Map[ Position[els, # ] &, common ] ; corr[[ Flatten[u] ]] = 1.13 This can be fit in a single line, and is almost readable corr[[ Flatten[ Position[els, # ] & /@ Intersection[elList, els] ] ]] = 1.13 and will seem even more nice if you use (elList ...


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 ...



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