Tag Info

Hot answers tagged

14

The "canonical" way in Mathematica is f[x_, y_] := x^2 + y^2 g[x_, y_] := x^4 + 4 x y + 2 y^4 - 8 Maximize[{f[x, y], g[x, y] == 0}, {x, y}] If you want to make explicit usage of the Lagrange multiplier: ss = N@Solve[Grad[f[x, y] + λ g[x, y], {x, y}] == 0 && g[x, y] == 0, {x, y, λ}, Reals] gives the {x, y} coordinates of the maxs and mins. ...


11

NMinimize does not work with ElementMesh (which is not RegionQ) directly. Perhaps it could, but for now I would suggest converting the element mesh to a region: NMinimize[x^2 + y^2, {x, y} \[Element] MeshRegion[disk]] This will work in Mathematica 10.0.2 and later.


9

Here is a linear programming surrogate that seems to do tolerably well. I'll show the code for your example but with a different cost function. I use 0-1 variables v[j,k] to indicate vertex j gets item k. edges = {{1, 2}, {2, 3}, {1, 4}, {2, 5}, {4, 5}, {3, 6}, {5, 6}, {4, 7}, {7, 8}, {5, 8}, {6, 9}, {8, 9}}; klpairs = With[{pairs = ...


8

NMinimize[{Norm[{xm[t][p], ym[t][p]} - {xsc[t][p], ysc[t][p]}] /. soln, 0 < t < tmax && 0 < p < 5}, {t, p}, Method -> "SimulatedAnnealing"] (* {71729.9, {t -> 118.095, p -> 5.}} *)


3

I applied Rationalize to every decimal constant feeding into the computation of Soln and rm, and replaced AccuracyGoal -> 10, PrecisionGoal -> 10 by WorkingPrecision -> 60. The change in rm was negligible, {3.69158*10^6, {t -> 2.10981*10^7, p -> 0.938622}} before, and {3.69179*10^6, {t -> 2.10981*10^7, p -> 0.938622}} after these ...


3

There will be an infinite number of functions. You could approach as follows: f[a_, b_, c_, d_, x_] := a*Log[b*x + c] + d then FindInstance[{f[a, b, c, d, 0] == 1, f[a, b, c, d, 80] == 0.5}, {a, b, c, d}, Reals] this yields: {{a -> 7.95441, b -> -0.098772, c -> 1297/10, d -> -(377/10)}} or sol = First[Quiet@Solve[{f[a, b, c, d, 0] == ...


3

I did some experimentation on Metropolis-Hastings algorithm for stochastic minimization of the cost function: ClearAll@mhGraphPairwiseMinimize; (* minimize sum of per-edge costs (computed as pairwise vertex item distances) by assigning items to vertices in a graph, using a Metropolis-Hastings algorithm. higher alpha makes random walk penalize ...


3

a = 1; b = 5; c = 12; (* version 10 *) StringTemplate["`1`-`2`-`3`.mx"][a, b, c] (* "1-5-12.mx" *) (* 10 and lower *) StringJoin @@ Riffle[ToString /@ {a, b, c}, "-"] <> ".mx" (* "1-5-12.mx" *)


2

As indicated by the comments by Michael E2 the new behavior is fine and still illustrates how specifying an initial interval can improve the optimum found. The specific change is due to improvements in the implementation, chiefly owing to the Automatic method strategy being switched from "NelderMead" to "DifferentialEvolution" for one-dimensional problems, ...


1

Apparently, for certain values of v, (the automatic method/options of) NMaximize fail(s) because the objective function becomes too complicated. In addition, your constraints are not set properly. For example, you allow $a_1$ and $a_3$ to be equal to $0$ even though they appear as part of denominators. (The outliers seem to be generated with NMaximize ...



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