Hey guys. So I have four matrices that are each 8 by 8: matrix P, matrix Q, matrix R, and matrix G. I have a certain algorithm (I wont go in to too much details about it because its too complicated with multiple files) that depends on those four matrices and uses them to output a single column of values for me. I also have what I call the perfect output, which is what I desire the output single column to look like. Now my question is: How can I use MATLAB to tune those 4 matrices in order for the output column to match the perfect output column?

댓글 수: 8

Dyuman Joshi
Dyuman Joshi 2023년 9월 26일
편집: Dyuman Joshi 2023년 9월 26일
It is difficult to comment without any specific information.
"I also have what I call the perfect output, which is what I desire the output single column to look like."
What exactly is your "perfect output"? or what are its characteristics?
Maybe try reshape
Ali Almakhmari
Ali Almakhmari 2023년 9월 26일
편집: Ali Almakhmari 2023년 9월 26일
The perfect output has the exact same format as (single column of values) the estimated output. It just has the desired values of the column output that I would like to estimation to be as close to as possible.
Torsten
Torsten 2023년 9월 26일
편집: Torsten 2023년 9월 26일
How can I use MATLAB to tune those 4 matrices in order for the output column to match the perfect output column?
And what are the "free tuning parameters" ? All 4*8*8 matrix entries of the 4 matrices ? Or only some of them and the others are derived from these "free" parameters ?
Ali Almakhmari
Ali Almakhmari 2023년 9월 26일
pretty much all of them yes
What is the length of the so-called "Perfect Output" column vector?
numParams = 4*8^2
numParams = 256
If you can mathematically map the 256 free parameters to each element in the Output column vector without any constraint, then solving the problem should be relatively straightforward, isn't it?
As I said use lsqnonlin
% Initialize P, Q, R, G
x0 = cat(3, P, Q, R, G);
lsqnonlin(@(x) computeOutput(x(:,:,1), x(:,:,2), x(:,:,3), x(:,:,4))-perfectoutput, x0);
function output = computeOutput(P, Q, R, G)
% Out your complicated here.
end
Ali Almakhmari
Ali Almakhmari 2023년 9월 26일
The length of the output is 314.
The code is looking good. 👍
% Initialize P, Q, R, G
P = [0.5 2.5; 3.5 1.5];
Q = P;
R = Q;
G = R;
perfectoutput = [1; 81; 256; 16];
x0 = cat(3, P, Q, R, G);
lsqnonlin(@(x) computeOutput(x(:,:,1), x(:,:,2), x(:,:,3), x(:,:,4)) - perfectoutput, x0)
Warning: Trust-region-reflective algorithm requires at least as many equations as variables; using Levenberg-Marquardt algorithm instead.
Local minimum found. Optimization completed because the size of the gradient is less than 1e-4 times the value of the function tolerance.
ans =
ans(:,:,1) = 1.0000 4.0000 3.0000 2.0000 ans(:,:,2) = 1.0000 4.0000 3.0000 2.0000 ans(:,:,3) = 1.0000 4.0000 3.0000 2.0000 ans(:,:,4) = 1.0000 4.0000 3.0000 2.0000
function output = computeOutput(P, Q, R, G)
M = P.*Q.*R.*G;
output = [M(1); M(2); M(3); M(4)];
end

댓글을 달려면 로그인하십시오.

 채택된 답변

Bruno Luong
Bruno Luong 2023년 9월 26일
편집: Bruno Luong 2023년 9월 26일

1 개 추천

Use lsqnonlin (or such) if you have optimization toolbox.

추가 답변 (0개)

카테고리

제품

릴리스

R2022b

질문:

2023년 9월 26일

댓글:

2023년 9월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by