Function with many outputs

2 次查看(过去 30 天)
B.E.
B.E. 2023-1-26
评论: B.E. 2023-1-26
I have this function [Y_1,Y_2,Y_3,Y_4]=MyFun(X);
I want to optimize X according to this cost function using ga function of Matlab
J=@(X) Y_1.^2+Y_2.^2;
X=ga(J,numel(X));
How to write the cost function J knowing that Y_1 and Y_2 depend on X.

采纳的回答

Torsten
Torsten 2023-1-26
X=ga(@cost,numel(X));
function J = cost(X);
[Y_1,Y_2] = MyFun(X);
J = Y_1.^2+Y_2.^2;
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Problem-Based Optimization Setup 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by