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
```