11 votes
Accepted

Markov (Chain) image generators?

I've implemented this recently, basically it counts how many times each specific colour borders another colour to make up a frequency table. To generate an image, a random colour and position are ...
Jonno_FTW's user avatar
  • 226
5 votes
Accepted

Solving constrained odes's using inbuilt solvers in Matlab/Octave

Yes you can. If the term that multiplies $N$ is never zero, then $N$ is an algebraic variable of index 1. Its combination with the ODEs on $x$ yields a system of differentiel-algebraic equations (DAEs)...
Laurent90's user avatar
  • 1,878
5 votes
Accepted

sum of absolute difference constraint in optimization problem

The way to deal with this kind of constraint is to add "slack variables" to your system. In your case, let us say that you want to solve the problem $$ \min_a c^T a \\ \text{subject to}\; \sum_{i=...
Wolfgang Bangerth's user avatar
4 votes
Accepted

Projection on Stiefel manifold after integration step

As a matter of fact, if you project each Runge-Kutta stage you will (in general) reduce the method to first order accuracy; this effect is similar to the order reduction that can occur due to boundary ...
David Ketcheson's user avatar
4 votes

Constrained simulated annealing

Simulated annealing comes from computations in statistical mechanics. When I think of simulated annealing, I very much think in terms of physics: I want to minimize some potential energy function that ...
doetoe's user avatar
  • 593
4 votes
Accepted

Constraints 'exactly/at most one non-zero element' without binary variables

No, this is not possible. There is a standard way of showing this: The feasible region of your constraints is not convex. For example, $x_{1,1}=1$, $x_{1,2}=0$ is feasible, $x_{1,1}=0$, $x_{1,2}=1$ ...
Brian Borchers's user avatar
3 votes
Accepted

Setting up optimization problem in GEKKO

A good first step with any parameter estimation problem is to solve it in simulation to verify that you can get a good solution and that the parameters have an effect on the objective. You can first ...
John Hedengren's user avatar
3 votes
Accepted

What are the various methods in adding an additional constraint to the quadratic spline interpolation problem

End slope for quadratic splines is a generalization of the natural quadratic spline condition: $p'_0(x_0) = v_0$. Alternatively, you could specify instead $p'_n(x_{n+1}) = v_{n+1}$. Since $\mathcal{C}...
helloworld922's user avatar
3 votes

How to get all intersections between two simple polygons in O(n+k)

In the general case, this cannot be done in $O(n+k)$ time, as there can be as many as $4\lfloor\frac{n}{2}\rfloor\lfloor\frac{k}{2}\rfloor$, i.e., Θ(nk) intersection points. If the two polygons are ...
HelloGoodbye's user avatar
2 votes

Simple methods for solving 2D steady incompressible flow?

I cannot comment, so as an answer may I recommend looking at something like: http://lorenabarba.com/blog/cfd-python-12-steps-to-navier-stokes/ form start to finish? This takes the reader from basic ...
DrHansGruber's user avatar
2 votes

Trajectory optimization for smoothness

You will have to transcribe the control problem in some manner so that you can feed it to a non-linear programming solver. You may want to look at Matthew Kelly's paper for a good introduction to ...
Paul's user avatar
  • 12k
2 votes

Making difference of log constraints convex

Let $z_i = \log p_i$ (i.e. $p_i = e^{z_i}$) and everything changes to linear constraints except the constraint $\sum e^{z_i} = 1$ which you can relax to $\sum e^{z_i} \leq 1$ since it will be tight at ...
Johan Löfberg's user avatar
2 votes

Making difference of log constraints convex

The constraints are not convex. Consider the example below in which x1 and x2 are each vectors of 3 elements which satisfy the inequality in question, as shown. 0.5(x1 + x2) does not satisfy the ...
Mark L. Stone's user avatar
2 votes

Linear constraints for L-BFGS-B

One approach to this problem is to reparameterize your problem in terms of $x_{1}$ and $z_{i}=x_{i}-x_{i-1}$, $i=2, \ldots, n-1$. You can then rewrite your objective function in terms of the the ...
Brian Borchers's user avatar
2 votes
Accepted

How to best code a problem with scipy, cvxpy or Convex.jl with given generated data

With your constraints of $a = 1$ and $c = -\frac{b}{d} - 1$, your $f$ looks like this: $$\hat{\mathbf{y}} = f(\mathbf{x},b,d) = \frac{bd}{d\exp{(\mathbf{x})}-b - d} + d$$ You're trying to solve a ...
Mithridates the Great's user avatar
2 votes
Accepted

Is there a way to bound the values of a variable when using scipy.integrate.solve_ivp in python?

If the exact solution indeed stays within [0,1], the solver may still resolve too coarsely the dynamics and "jump" over the physical bounds. One way to solve this is to use lower absolute ...
Laurent90's user avatar
  • 1,878
2 votes
Accepted

Constraint programming problem with conditional constraints and some unknown indicator variables

You should have a look at Satisfiability Modulo Theories or SMT for short. A huge number of problems can be thought of as instances of SMT for a particular theory. For example, correctly designing ...
Daniel Shapero's user avatar
2 votes

Solve integral equation for unknown constant

Like what @Kirill says, write a script that defines $f(u)$ to be a function that approximates the integral. Thus all that you need to is solve $f(u)=0$ which can use standard root finding tools like ...
Chris Rackauckas's user avatar
1 vote

Defining a soft constraint in cvxpy

EDIT: Intermediate solution ...
ThatQuantDude's user avatar
1 vote

Markov (Chain) image generators?

Blog post on an experimentation using Markov to recreate art: https://magenta.as/using-machine-learning-to-make-art-84df7d3bb911 Code is on github made by @william-index: https://github.com/william-...
Gustavo Faria's user avatar
1 vote

Newton's method with box-constraints

You should put "mirrors" to bracket your domain. For example, in a one-dimensional case: If I know that my unknown $x$ is bounded between $0$ and $a$. At each iteration of my method, i will check if ...
T. Auerrac's user avatar
1 vote
Accepted

Eigenvalue problem constrained with a penalty method

I found the error, I just need to constrain the implied identity matrix on the right-hand-side too: ...
user1941126's user avatar
1 vote

Simple methods for solving 2D steady incompressible flow?

Ironically, there is an iterative method called "SIMPLE" (semi-implicit method for pressure-linked equations) designed to resolve the steady state navier-stokes equations based on a predictor-...
Paul's user avatar
  • 12k
1 vote

Simple methods for solving 2D steady incompressible flow?

With the continuity eqn only, you are missing all the mechanical balance: viscous and/or inertial effects will decide of the streamlines of such a flow. If your major aim is to keep it as simple as ...
Joce's user avatar
  • 362
1 vote

How to handle the quadratic constraint $x y \leq z$?

To me it looks you are dealing with a standard Geometric Program (GP) which can be handled easily by commercial solvers (see e.g. https://www.cvxpy.org/tutorial/dgp/index.html)
Apprentice's user avatar
1 vote

How to handle the quadratic constraint $x y \leq z$?

If this is the only relevant part of your problem, you can write this as a semidefinite program. Since $x_1, x_2$ do not appear individually you can treat it as a square of a positive number then your ...
percusse's user avatar
  • 393
1 vote

Nonlinear least squares with box constraints

The R minpack.lm CRAN package provides a Levenberg-Marquardt implementation with box constraints. In general, Levenberg-Marquardt is much better suited than L-BFGS-B for least-squares problems. It ...
jherek's user avatar
  • 121
1 vote

Nonlinear least squares with box constraints

(Years later) two solvers that handle box constraints: Scipy least_squares has 3 methods, with extensive doc: 'trf’: Trust Region Reflective 'dogbox' 'lm': a legacy wrapper for MINPACK, without box ...
denis's user avatar
  • 932

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