Hello, I have the problem, that I want to create a symbolic equation system, e.g. in the form of A*B = C(where A and C are known matrices and B is unknown) and then pass the whole system to a solver like fmincon (because the final system will not be constructed in a linear manner).
My approach was to have a nested function in the following way:
function xsol = test1()x0 = [1 1 1 1 1 1 1 1 1];lb = [-100 -100 -100 -100 -100 -100 -100 -100 -100];ub = [100 100 100 100 100 100 100 100 100];options = optimset('Display', 'off');A = sym('A', [3 3]);B = randn(3,3);eq = A*B;xsol = fmincon(@test12,x0, [], [], [], [], lb, ub, [], options);function fmin =test12(A)fmin = (sum(sum(abs(eq))));endend
So the equation system is created and then passed to the objective function (test12), which is minimizing the sum of all Values in A. Unfortunately this results in the error "FMINCON requires all values returned by user functions to be of data type double."
If on the other hand, I create the equation system in a first step and the copy the content of eq in the constraint function, it works without a problem. Reading out the symbolic matrix and copying it to the objective function manually is something I would like to avoid, as I want to solve the system for many different A matrices.
Is there a way to evaluate the symbolic quation system eq in a way, that it is solvable like that? My matlab Version is 2014b
Thank you for your help
Cheers
Best Answer