optimizing each element of a matrix based on the elements of another matrix
7 ビュー (過去 30 日間)
古いコメントを表示
Hi MATLAB experts,
I have an objective function which is a matrix. Each element of this matrix is a function of another matrix, as it is shown in the code below. "objfun(i,j,m,k)" is a function of "ptilda (i,j,k,m)" for all k,m,i,j but I would like to maximize this specific objfun (I mean for a specific i,j,m,k) w.r.t "ptilda (i,j,k,m)".
Any idea, how I can do that?
I am using fmincon() and getting the following error:
Supplied objective function must return a scalar value.
So, I guess I should go for gamultiobj (), rigth? But I don't know how to implement that. rigth now my constraints are in the format of
lb <= ptilda <= ub and A*ptilda <= b and c(ptilda)<= 0
where ptilda is a matrix of size (max(I(:)), numel(I), numel(M), max(M(:))).
If I use gamultiobj(), how will the constraints change?
Thanks in advance. Your help would be greatly appreciated.
objfun = zeros(max(I(:)), numel(I), numel(M), max(M(:)));
for k = 1 : K
for m = 1 : M(k)
for j = 1 : J
for i = 1 : I(j)
objfun(i,j,m,k) = G(ptilda (i,j,k,m));% is a function of ptilda (i,j,k,m)
end
end
end
end
回答 (1 件)
Shishir Reddy
2024 年 12 月 26 日 9:44
Hi Susan
To maximize your objective function for each specific (i, j, m, k) with respect to ptilda(i, j, k, m), your problem has to be reformulated such that each optimization targets a specific element of objfun. Since fmincon is designed for scalar objective functions, you need to structure your optimization problem so that each call to fmincon (or equivalent) targets a single element of objfun.
Defining a scalar objective function -
scalarObjective = @(ptilda_value) -G(ptilda_value); % Negative for maximization
Performing optimization -
for k = 1:K
for m = 1:M(k)
for j = 1:J
for i = 1:I(j)
ptilda_initial = ptilda(i, j, k, m); % Initial guess
nonlincon = @(ptilda_value) c(ptilda_value);
options = optimoptions('fmincon', 'Display', 'off');
[opt_ptilda, fval] = fmincon(scalarObjective, ptilda_initial, A, b, [], [], lb, ub, nonlincon, options);
ptilda(i, j, k, m) = opt_ptilda;
objfun(i, j, m, k) = -fval; % Store the maximized value
end
end
end
end
For more information regarding optimoptions and fmincon, kindly refer the following documentations
I hope this helps.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Computations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!