I'm trying to pass a symprod() as the function variable for fmincon() and getting quite a few errors.
For example, if my code is like so:
func = @(t, x, z) symprod(abs(u - t), u, x, z);fmincon(func(1, 2, 4), 0, [], [], [], [], -1, 1)
I get the errors
Error using optimfcnchk (line 93) If FUN is a MATLAB object, it must have an feval method.Error in fmincon (line 399) funfcn = optimfcnchk(FUN,'fmincon',length(varargin),funValCheck,flags.grad,flags.hess,false,Algorithm);Error in A6test (line 4) fmincon((func(1, 2, 4)), 0, [], [], [], [], -10, 10)
So, looking at the first error, I discovered I could us matlabFunction() to bypass it. Naturally, I tried that:
syms ufunc = @(t, x, z) symprod(abs(u - t), u, x, z);fmincon(matlabFunction(func(1, 2, 4)), 0, [], [], [], [], -1, 1)
However, now I get a set of different errors
Error using symengine>@()6.0 Too many input arguments.Error in fmincon (line 536) initVals.f = feval(funfcn{3},X,varargin{:});Error in A6test (line 4) fmincon(matlabFunction(func(1, 2, 4)), 0, [], [], [], [], -10, 10)Caused by: Failure in initial objective function evaluation. FMINCON cannot continue.
The first of these is pretty self-explanatory but I am pretty sure that the amount of variable inputs is correct. Thus, it leaves me thinking that matlabFunction() does not work here and I need a different solution to my problem, or a whole different method of tackling how to pass symprod() to fmincon(). Any and all help would be greatly appreciated.
Best Answer