MATLAB Answers

Optimisation problem in matlab

1 ビュー (過去 30 日間)
wallflower
wallflower 2021 年 6 月 21 日
編集済み: Sergey Kasyanov 2021 年 6 月 24 日
Hello guys,
So I have this scatte plot in the form of a measured impedance according to frequency Z(f), and I have an RL ladder circuit seen in the following figure
.
I need some help in writing an optimisation problem that will allow me to get the values of the parameters R_i L_i that will eventually give an equivalent impedance of the RL ladder similar to the one measured- Z(f) -.
Thanks in advance.
Wallflower
  2 件のコメント
wallflower
wallflower 2021 年 6 月 21 日
It is not a homework assignment. I am trying to reproduce a methology I've seen in a scientific paper.

サインインしてコメントする。

回答 (1 件)

Sergey Kasyanov
Sergey Kasyanov 2021 年 6 月 21 日
編集済み: Sergey Kasyanov 2021 年 6 月 24 日
Hello!
Try that:
% tune only next 2 lines
L = 5;% steps in ladder
Z_max = 1e2;% max Z for one R or Xl
% goal Z(w)
% w0 - array with measured angular frequences
% Z0 - array with measured impedances
% R0 - Rs_1.txt
% L0 - 2*Self_Energy_1.txt
w0 = (2.*pi.*[[1e-3,50,500],1e3:2e3:500e3])';
Z0 = R0(:,1) + 1i*w0.*L0(:,1);
w0 = reshape(w0, 1, []);
Z0 = reshape(Z0, 1, []);
%% calculate z(w) for ladder
R = sym('R', [1,L+1]);
L = sym('L', [1,length(R)]);
w = sym('w');
par = @(a, b) 1/(1/a + 1/b);
h1 = @(a, i) R(i) + par(a, 1i*w*L(i));
Z = R(end);
for i = (length(R)-1):-1:1
Z = h1(Z, i);
end
% get lambda function for optimization
fun1 = matlabFunction(Z);
% do not look at that code
s = 'fun2 = @(vals, w) fun1(';
for i = 1:(length(R)*2 - 1)
s = [s, sprintf('vals(%i), ', i)];
end
s = [s, 'w);'];
eval(s);
% create optimization function
fun3 = @(vals) sum(abs(fun2(vals, w0) - Z0).^2);
% number of variables
N = length(symvar(Z)) - 1;
%the better way is to use more powerfull algorithms such as genetic algoritms which can stands
%against a huge amount of local min. There are a lot of algorithms that
%realized in matlab toolboxes. Try!
options = optimoptions('ga', 'Display', 'iter', 'PopulationSize', N*200, 'MaxGenerations', N*200);
res = ga(fun3, N, [], [], [], [], zeros(1, N), Z_max*[ones(1,floor(N/2))/2/pi, ones(1, ceil(N/2))], [], options);
% first floor(N/2) of res - L(1), L(2), ...
% last ceil(N/2) of res - R(1), R(2), ...
%plot results
figure;plot(w0, abs(Z0), w0, abs(fun2(res,w0)));
figure;plot(w0, angle(Z0), w0, angle(fun2(res,w0)));
  10 件のコメント
Sergey Kasyanov
Sergey Kasyanov 2021 年 6 月 24 日
I corrected code. There were some misprints.
Now it is working, but It is very sensitive to limits of Z_max and amount of ladder steps. Try, please. Does it working on your machine?

サインインしてコメントする。

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by