40 votes
Accepted

Max & min distance between two moving points

...
MarcoB's user avatar
  • 67.2k
33 votes
Accepted

Optimization of function taking a permutation

How about a Monte-Carlo-Metropolis search? I'll implement a simplistic version here. See complete universal code further down. Update: Cleaned-up code now available in the Wolfram Function Repository, ...
Roman's user avatar
  • 47.5k
33 votes

Efficient multidimensional optimization while constraining some coordinates

Phew, this became more complex than I thought because the objective is not quadratic (as I had first expected). Here some preparations for an efficient evaluation of the energy and its first two ...
Henrik Schumacher's user avatar
22 votes

how to get $n$ equidistributed points on the unit sphere

If more ad hoc, inexact approaches are welcome, one way to generate relatively uniform density of points on a sphere is to use Monte Carlo Lloyd's algorithm (modified for the spherical case): ...
kirma's user avatar
  • 19.1k
20 votes

Expressing a polynomial as a sum of squares

Here is a somewhat heuristic approach, that relies in this case on the SOS having integer coefficients. I will indicate an alteration that gives a numerical approximation in the general case. Start ...
Daniel Lichtblau's user avatar
20 votes
Accepted

Possible bug in NMaximize function?

This is an extended comment rather than an answer, but it would have been unwieldy in a comment box. I was able to reproduce the problem you describe on Windows 10 / MMA 12. I also noticed that ...
MarcoB's user avatar
  • 67.2k
19 votes
Accepted

Scheduling Optimization

Turning a comment into an answer. This is more or less a straight-forward adaptation of a solution in Efficient solution for a discrete assignment problem with pairwise costs to the problem. This ...
kirma's user avatar
  • 19.1k
19 votes

Possible bug in NMaximize function?

In V12, WRI introduced new convex optimization solvers. NMiminize was updated to automatically choose one when appropriate. But in this case, it seems to enter an ...
Michael E2's user avatar
  • 236k
19 votes
Accepted

How can I use Python's SciPy and NumPy functions in Mathematica to find the minimum of a function?

I believe you're not in the correct direction, optimizing your Mathematica code should be more practical and easier. (You've already learned the numeric capability of Mathematica under your previous ...
xzczd's user avatar
  • 66k
19 votes
Accepted

Efficiently Mowing Grass with Mathematica

This is just starting ideas for arbitrary regions. Perhaps you can improve it. Version 1 Define concave region with holes, which can be generalizable to arbitrary complexity: ...
Vitaliy Kaurov's user avatar
18 votes
Accepted

Why can't I provide NMinimize with initial points when minimizing over two variables but not one?

Feed "InitialPoints" a list of 1D vectors: ...
Michael E2's user avatar
  • 236k
18 votes
Accepted

Minimum energy path of a potential energy surface

Smooth Equations Let $\varphi \colon \mathbb{R}^d \to \mathbb{R}$ denote a potential function (e.g., from OP's data file). We attempt to solve the system $$ \left\{ \begin{aligned} \gamma(0) &...
Henrik Schumacher's user avatar
18 votes
Accepted

Find the equidistance curve between two curves

f[x_] := x^x g[x_] := Log[x]^Log[x] h[x_] := Log[x]^2 plot = Plot[{f[x], g[x], h[x]}, {x, 0, E}, PlotRange -> {0, 1}] Extract the three lines from ...
kglr's user avatar
  • 395k
18 votes

Find the equidistance curve between two curves

Here we manual create the normal line of the three differentiable curves. ...
cvgmt's user avatar
  • 72.7k
16 votes
Accepted

how to get $n$ equidistributed points on the unit sphere

Aha~ I suppose this question is created while solving this. Am I correct @yode :P So here's an easy solution, simple, elegant, and may I say even quite fast after some optimization? ...
Wjx's user avatar
  • 9,558
16 votes

Solving optimal control problem when input is constrained

Semi-smooth Newton solver This is supposed to solve constrained optimization problems of the form $$ \text{Minimize } F(x) \text{ subject to } \varPhi(x) = 0 \text{ and } \varPsi(x) \leq 0.$$ More ...
Henrik Schumacher's user avatar
16 votes
Accepted

Given a list of integers, find the largest sum of a contiguous subsequence

f[l_] := Module[{sl = Flatten@MaximalBy[Subsequences[l], Total]}, {Total[sl], sl}] f[{1, 2, 3, 4, 5, -1, 7, -4, -2}] (* {21, {1, 2, 3, 4, 5, -1, 7}} *)
bbgodfrey's user avatar
  • 61.4k
16 votes
Accepted

Finding an ellipse of minimum area that encloses a set of points

You are looking for BoundingRegion with the "MinEllipse" region specification: ...
MarcoB's user avatar
  • 67.2k
15 votes
Accepted

Minimizing with differential evolution

Here's a way: ...
Michael E2's user avatar
  • 236k
15 votes
Accepted

Packing arbitrary shapes

Perhaps a start: We can extract information from WordCloud in order to translate a collection of regions so they pack nicely. First I'll create some ...
Greg Hurst's user avatar
  • 35.9k
15 votes

Why does NMaximize miss this global maximum?

This kind of problem — smooth, univariate function over a finite and relatively small domain — can be handled numerically by using NDSolve to locate the relative ...
Michael E2's user avatar
  • 236k
15 votes
Accepted

Genetic algorithm to maximize a function $\text{Sinc}(x)$

You could do so many different things for crossover and mutation, like toggling/interchanging bits in the binary representation of $x$ or whatever - but here I've just used an average for crossover, ...
flinty's user avatar
  • 25.3k
14 votes
Accepted

Numerical optimal control

Oh boy, what a question! This is very similar to some stuff I played a few weeks ago (Kerbal, what a game!). What follows solves (I think) the question you are asking. An approach that seemed to to ...
Quantum_Oli's user avatar
  • 7,964
14 votes
Accepted

Using StepMonitor/EvaluationMonitor with DifferentialEvolution in NMinimize

EvaluationMonitor is going to be called whenever the objective function is being evaluated, that is much more often than ...
ilian's user avatar
  • 25.5k
14 votes

Differentiating functions of vectors/matrices?

In this post I discuss a function MatrixD which attempts to take a matrix derivative following the guidelines given in the The Matrix Cookbook. I still want to ...
Carl Woll's user avatar
  • 131k
14 votes
Accepted

FindMaximum of Interpolated data set

NMaximize is good for finding global maxima: NMaximize[{f[x], 26 < x < 6908}, x] (* {28.9179, {x -> 177.957}} *) For <...
aardvark2012's user avatar
  • 5,424
14 votes

Minimum energy path of a potential energy surface

Interesting problem. Decided to treat it as a graph problem, rather than fitting an InterpolatingFunction to it and getting descent directions from there. If I knew ...
MikeY's user avatar
  • 7,153
14 votes
Accepted

Minimizing expression over symmetric matrices

That's an eigenvalue problem! How to see that? Well, let's define some example data: ...
Henrik Schumacher's user avatar
14 votes
Accepted

Maximizing over a 1D region

Update: Carl gave the best solution in a comment: Could use {y} ∈ Interval[{-1, 1}] instead. – Carl Woll If you use the region notation, the variable is ...
Szabolcs's user avatar
  • 235k
14 votes
Accepted

Finding the largest disk within a convex region using Region primitives

poly = Polygon @ {{0, 1}, {0, 6}, {4, 10}, {8, 10}, {11, 7}, {11, 4}, {7, 0}, {1, 0}, {0, 1}}; dsk = Disk[{x, y}, r]; We can use ...
kglr's user avatar
  • 395k

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