How to define a multivariable function (for instance an anonymous function) of a number of variables that varies according to the size of an array variable?

My aim is to compute the point of minimum value for a function which is a determinant of the product of 3 matrices where the columns of the first and third are functions of a variable each.

 Accepted Answer

Define your function as
function y = myfun(a,b)
A = [-a a; a -a]; % sample definition
B = rand(2);
C = [-2*b b; -4*b b]
y=det(A*B*C)
Use fminsearch to find the minimum of that function.

1 Comment

Thank you so much for your effort. The problem with this answer is that the number of variables on the call to the function is 2 but in my case is p which is the size of the matrice of data. It's not possible to call the function with x1,x2,...,xp. Do you have any idea of how to circumvent this?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!