Fmincon error: pivot is zero


I am using GNU Octave to run a optimization code (called find_initvalues_speed ) on my Raspberry Pi. The code was originally written in Matlab and uses fmincon to solve a constrained optimization problem. When I run the code fmincon starts iterating before suddenly showing the following error. The code works as expected with Matlab. Do you have any input on what may be causing this error?

error: pivot is zero
error: called from
gjp at line 42 column 5
cpiv_bard at line 59 column 9
lm_feasible at line 302 column 31
fmincon at line 451 column 24
find_initvalues_speed at line 40 column 2

Line 40 from find_initvalues_speed :

1 Like

You can try another “active-set” algorithm, as ‘fmincon’ from the optim package uses a strictly feasible interior-point algorithm by default, which might be too strict in your case. With a minimal complete example it is easier to help :thinking:

Of course. I have machine that shoots footballs with a desired speed, sidespin and angle. The machine angle can be set and the ball is shot between two wheels which have independent speeds. I am making an optimization algorithm to calculate how the machine should be set to reach a desired landing point, based on a ball model which was derived by my peer. This model has some parameters which may be tuned. This script works well i Matlab with default interior-point algorithm, but I wish to convert it to Octave to run it on Raspberry Pi.

To get the optimal solution I call find_initvalues(p_f, kd, kl, kw) where p_f is the desired landing point in XYZ coordinates relative to the machine and the k-values are the selected model parameters.
The equality constraints and lower and upper bound are set in Aeq,beq,lb,ub (these are constant).

function [optimal_x] = find_initvalues(p_w,k_d,k_l,k_w)

global p_f t_p
% x=[v_0;theta;psi;omega;lambda;gamma;x_f;y_f;z_f]

Aeq=[0 0 0 0 0 0 0 0 0 ;
     0 1 0 0 0 0 0 0 0 ;
     0 0 0 0 0 0 0 0 0 ;
     0 0 0 1 0 0 0 0 0 ;
     0 0 0 0 1 0 0 0 0 ;
     0 0 0 0 0 1 0 0 0 ;
     0 0 0 0 0 0 1 0 0 ;
     0 0 0 0 0 0 0 1 0 ;
     0 0 0 0 0 0 0 0 1];



Minfunction takes a set of initial conditions, x, and simulates the according ballpath it will produce using Simulate_ballpath. This simulation has been tested separately in Octave and works well. This produces a y_s which contains data about the ball in each position in the ball path.

The point in the ballpath with the shortest distance to the desired landing point p_f is found in a for loop. This point is then evaluated in a cost function with a resulting cost f. The initial conditions x which corresponds to the ball path which produces the lowest cost is selected by fmincon.

Debugging in minfunction shows that fmincon is able to solve and save the cost in fplot approx 12 times before it exits and shows the bug. The bug keeps showing for all different arguments that i pass to find_initvalues. Any input on how I could debug this?

function [ f ] = minfunction( x )
global minindex fplot p_f j
path=aboveground(y_s(:,1:3)); %path stops when z<0
%for distance, speed, time
%for each direction, total speed, spin
%Get number of points in path
for i=1:m
  if currentdist<tempmin
if tempmin<=Inf
	fplot=[fplot f];

@laksi Thank you for the code. Unfortunately, the given example is incomplete and I cannot run it on my system to experiment. It seems to be snippets out of a larger project. Do you have public access to your whole project somewhere on GitHub or alike?

Otherwise I can only give my previous advice.

Hey, thats correct. I rarely post in forums so I figured it would be better to not post the all the files in my post. Here is the git repo(under new_optimalisering): footballmachine/optimalisering/new_optimalisering at main · laksiya/footballmachine · GitHub

Run initialize., then examplex.m
Then you should be able to run find_initvalues_speed(x(1:3),x(4),x(5)) and see the error

Rund find_initvalues_speed(input(1:3),input(4),input(5)) and see the error.
x is the expected answer
input(1:3) could be replaced with other corrdinates [X,Y,Z] where Y is set as the direction of the ball shooter.

Here are the commands needed to calculate the optimal path and simulate + plot it. The error is in find_initvalues_speed as mentioned before

>ans= find_initvalues_speed(input(1:3),input(4),input(5))
>[ T_s,Y_s ] = Simulate_ballpath(x);