How to use an optimization expression if in a function?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Diego Cecchinato
el 17 de Jul. de 2020
Editada: Diego Cecchinato
el 20 de Jul. de 2020
Hi everyone!
I'm new to Matlab and i'm trying to write a function that is used in a problem based optimization.
This is the code that i wrote:
function [array] = getmax (matrix)
row = size(matrix,1);
column = size(matrix,2);
array = optimexpr;
for i=1:1:row
maxr = 0;
for j=1:1:column
if matrix(i,j) >= maxr
maxr = matrix(i,j)
end
end
array(i,1) = maxr;
end
end
Matrix is an optimization expression (es. 4 row and 5 column)
Array is the optimization expression that i want to get as the result of the function. (in this example it should be 4 row 1 column with tha max value of each matrix's row).
If i run this code i get "Conversion to logical from optim.problemdef.OptimizationInequality is not possible" in the if line.
I read about the big-M method, but i can't apply that method to my problem. (There's a lot about the big-M method for constrain but not a lot for function).
Can someone help me? I think it's a very simple function but i'm a newbie :(
Thanks
0 comentarios
Respuesta aceptada
Matt J
el 17 de Jul. de 2020
You cannot express such an operation through the problem-based framework. If you are trying to solve a minimax problem, then you should use fminimax()
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

