8

You could use StepMonitor to check if we reached our goal and then Throw / Catch to stop. Here is test example, where we print x,y, and the change of the function. fun[x_, y_] = -x^4 - y^4 + x y + x^2 y; last = {0, 0}; FindMaximum[fun[x, y], {x, y}, StepMonitor :> Print[{x, y, Norm[last - {x, y}]}]] We now add Throwand Catchto stopp when the difference ...


5

Consider your equations: f = Exp[-(x[t] - xend)^2] x'[t] == -(D[D[f, x[t]], x[t]])^-1 D[f, x[t]] x[0] == xstart If we evaluate this: If we now calculate x'[0]: (* -2/7 *) As this is the initial slope and is negative, the solution must fall at x==0, it can not increase. Maybe your equations are wrong.


4

Try this NMaximize[{k, (a + b + c + d + e + f + g + h + i + j + k == 1) && (b + 2*c + 3*d + 4*e + 5*f + 6*g + 7*h + 8*i + 9*j + 10*k == 6) && (b + 4*c + 9*d + 16*e + 25*f + 36*g + 49*h + 64*i + 81*j + 100*k == 42), ## & @@ Thread[{a, b, c, d, e, f, g, h, i, j, k} >= 0]}, {a, b, c, d, e, f, g, h, i, j, k}, Reals]...


3

NonNegativeIntegers is not a region,it is just a algebra field. You can use NMaximize[{k, a + b + c + d + e + f + g + h + i + j + k == 1, b + 2*c + 3*d + 4*e + 5*f + 6*g + 7*h + 8*i + 9*j + 10*k == 6, b + 4*c + 9*d + 16*e + 25*f + 36*g + 49*h + 64*i + 81*j + 100*k == 42}, {a, b, c, d, e, f, g, h, i, j, k} ∈ ImplicitRegion[ Thread[{a, b, c, d, ...


3

I think the problem is not neither the Do loop or the fact that the code is not compiled. (I think FindMinimum will try to compile if it can.) The problem seems to be rather that FindRoot is not good at handling VectorLessEqual. This is a quite new feature and so I was surprised that it existed. Rephrasing the inequality constraints "in the good ol' way&...


2

Note: I found that this answer doesn't actually work, but I'll leave it here as it provides some insight nonetheless. Upon surrounding different sections with Echo[AbsoluteTiming[...], "section-label", First][[2]], your Do loop actually seems quite fast (0.002 seconds on my machine). FindMinimum, however, takes quite a while. (To test this more ...


2

I am not sure if I understand you correctly. You want to minimize V12+V13+V23 over B1, B2, B3. What is the `While`` loop for? And as V12,V13,V23 are not independent, you must minimize them together, not separately. Anyway, this can be done by: r = 20.0; v12[B1_, B2_] = 10^6 r^-3 E^-r (-r^2 Cos[B1] Cos[B2] + r Sin[B1] Sin[B2]); v13[B1_, B3_] = 10^6 r^-3 ...


2

Perhaps ContourPlot helps to find the intersection points! Try e1= -0.0492101+(0.00982664*l3*Sec[147.557*l3]^2*(Tan[147.557*l8]+3.34665*Tan[152.139*l8]))/(Tan[152.139*l3]*Tan[147.557*l8]-Tan[147.557*l3]*Tan[152.139*l8])+(0.00982664*l8*Sec[147.557*l8]^2*(Cot[147.557*l8]*Tan[147.557*l3]+3.34665*Cot[147.557*l8]*Tan[152.139*l3]))/(-Tan[152.139*l3]+Cot[147.557*l8]...


2

With the linear term included the function is unbounded, i.e. there is no global maximum. Even without the linear term, Maximize does not work, so you must derive it. f[x_] = 1/(σ*Sqrt[2*Pi])*Exp[-1/2*(x - μ)^2/σ^2]; arg = Simplify[ Solve[{f'[x] == 0, f''[x] < 0}, x, Reals] // Flatten, σ > 0] (* {x -> μ} *) Or more simply for this case arg = ...


2

This works in 0.25 seconds. zetas=FullSimplify[zetas]; terminalcons=FullSimplify[terminalcons]; speccons=List@@{FullSimplify[speccons]/.(1.0->1)}; setcons={-1.0<=u51<=1.0,-10.0<=u52<=10.0}; FindMinimum[Flatten@{obj, speccons, terminalcons, setcons}, {u51, u52}] (* {0.660595,{u51->0.00600015,u52->0.04524}} *)


1

Clear["Global`*"] SeedRandom[1234]; data = RandomReal[{0, 10}, {20, 2}] // Sort; Manipulate[ peaks = data[[FindPeaks[data[[All, 2]], sigma, sh, th][[All, 1]]]]; ListPlot[data, Joined -> True, Epilog -> {Red, AbsolutePointSize[4], Point[peaks]}], {{sigma, 0}, 0, 4, 0.1, Appearance -> "Labeled"}, {{sh, 0, "...


1

Try setcons = And @@ Thread[{-15, -100} <= {0., 0. + 100 u51} <={15,100}] && -10 <= u51 <= 10 && -10 <= u52 <= 10 constraints = speccons && terminalcons && setcons; R = ImplicitRegion[constraints, {u51, u52}]; NArgMin[obj, {u51, u52} \[Element] R] (* {0.00600015, 0.0452401} *) RegionPlot[R]


1

u[c_, d_] := Sinh[a b^2 c^2 + 3 a b d]; v[c_, d_] := Log[a b^2 c^2 + 3 a b d + d^2] - d; w[c_, d_] := 2 a b c + 3 b c - 2 c d^2 + c*Exp[a + b]; NMaximize[{w[c, d], u[c, d] == 0, v[c, d] == 0, -3 <= a <= 3, 1 <= b <= 2}, {a, b, c, d}] {98.4569, {a -> 2.99992, b -> 1.14721, c -> 1.35641, d -> -0.703619}}


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