# Fmincon error: pivot is zero

Hi,

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 :
x=fmincon(âminfunctionâ,x_0,[],[],Aeq,beq,lb,ub);

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

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
p_f=p_w;
t_p=0:0.001:10;
% x=[v_0;theta;psi;omega;lambda;gamma;x_f;y_f;z_f]
lb=[1,-pi,0,-10,0,0,0,0,0];
ub=[27;pi;pi/2;10;pi/2;pi/2;10;10;10];

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];

beq=[0;0;0;0;0;0;k_d;k_l;k_w];
x_0=[10,0,45*pi/180,0,0,0,k_d,k_l,k_w];
x=fmincon('minfunction',x_0,[],[],Aeq,beq,lb,ub);
x_return=x;

end
``````

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
%y=[x,y,z,dx,dy,dz,v,omega,lambda,gamma;k_d;k_l;k_w];
[t_s,y_s]=Simulate_ballpath(x);
path=aboveground(y_s(:,1:3)); %path stops when z<0

%for distance, speed, time
gain=[1,0,0];
%for each direction, total speed, spin
dirgain=[1,10,1];
%Get number of points in path
[m,n]=size(path);
f=0;

tempmin=Inf;
for i=1:m
currentdist=dirgain(1)*(p_f(1)-path(i,1)).^2+dirgain(2)*(p_f(2)-path(i,2)).^2+dirgain(3)*(p_f(3)-path(i,3)).^2;
if currentdist<tempmin
tempmin=currentdist;
minindex=i;
end
end
if tempmin<=Inf
f=gain(1)*tempmin+gain(2)*x(1)+gain(3)*t_s(minindex);
fplot=[fplot f];
end

end``````

@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

Correction:
Rund find_initvalues_speed(input(1:3),input(4),input(5)) and see the error.
``````>initialize