How to extract calculated variable values from real-time optimization when using fmincon in simulink
조회 수: 2 (최근 30일)
이전 댓글 표시

The codes and statement typed below, i.e. before 'My Question' has been posted before. See below my 'My Question' for description of the problem
Let's see inside the regressor:
function [m, q] = regressor(xs, ys, mic, qic)
coder.extrinsic('opt_problem'); % <- Informing the Coder
m = 0;
q = 0;
[m, q] = opt_problem(xs, ys, mic, qic); % <- Optimal problem wrapper call
end
this function is only a wrapper for an external function `opt_problem`. Let'see it (it has two functions inside):
function [m, q] = opt_problem(xs, ys, mic, qic)
fmincon_target = @(mq)(target(mq, xs, ys));
mq = fmincon(fmincon_target, [mic; qic], [], [], [], [], [0; 0], [1; 1]);
m = mq(1);
q = mq(2);
end
function r = target(mq, xs, ys)
r = norm(ys - xs.*mq(1) - mq(2));
end
My Question
The problem above works fine, however I intend to extracted calculated value from the function 'target' in the 'opt_problem' function file. Therefore, lets say I rewrite the codes as follows:
function [m, q] = opt_problem(xs, ys, mic, qic)
fmincon_target = @(mq)(target(mq, xs, ys));
mq = fmincon(fmincon_target, [mic; qic], [], [], [], [], [0; 0], [1; 1]);
m = mq(1);
q = mq(2);
end
function r = target(mq, xs, ys)
Z = xs.*mq(1);
U = ys- mq(2);
r = norm(U-Z));
end
Then how do I extract the calculated Z and U so that they are also given as output of the 'regressor' block. Note, that in my problem the computation of Z and U is quite lenghten and it would be inefficient to calculate Z and U using the computed values of mq(1) and mq(2) in another block. Other alternative extraction are also welcomed.
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Block Libraries에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!