You need to parameterize your function calls:
You need to use function handles instead of strongly discouraged character vectors:
When you read the fmincon documenation it clearly states that the input function "fun is a function that accepts a vector or array x and returns a real scalar f", but you are providing functions with multiple input arguments, which is not supported by the documentation. Your functions need to have one input and one output argument, or whatever the documentation states. That is why the fmincon page links twice to this page:
so that you will know how to parameterize your function and pass all of those other inputs. For example, instead of this strongly discouraged and buggy syntax:
fmincon('costNMPC_Sla_AGL',...
you should be parameterizing a function handle to pass that data correctly, e.g. using an anonymous function:
A = ...
B = ...
...
E = ...
fmincon(@(u)costNMPC_Sla_AGL(u,A,B,C,D,E),...
where A, B, C, D, and E are the other five input arrays that you need to provide to that function.
Or use nested functions, if you prefer. Nested functions are simple and intuitive, although it requires putting all of the functions into one file:
Best Answer