📄 mimo_ub_lb.m
字号:
function mimo_ub_lb(fun,f,flag,y,vub,vlb,Epsilon,ps,ms,qs,qds,order,handle,...
L_handle,p_handle,input_delay,pds,Mp,decade)
% This function compute upper bound and lower bound of the MIMO system
% This funtion is used by function mimo_freq.m .
global Xwc_ub_w Xwc_lb_w Tune_flag
%clc
tic
x=(vub+vlb)/2;
n=length(order);
Tune_flag=zeros(1,n);
%y_limit=[str2num(get(L_handle(2),'String')) str2num(get(L_handle(1),'String'))];
[len,temp]=size(Xwc_ub_w{1,1});
if get(p_handle,'value')
f=figure;
else
figure(f);cla;
end
count=0;
for i=1:n
for j=1:n
bg_color=get(handle(n*(i-1)+j),'Backgroundcolor');
if ~all(bg_color==[1 1 1])
count=count+1;
end
end
end
h_wait=waitbar(0,'Please wait ...');
option=optimset('LargeScale','off','Display','off');
switch fun
case 'mimo1com'
constn='mimo1com_con';
case 'mimo2com'
constn='mimo2com_con';
case 'mimopartial'
constn='mimopartial_con';
end
switch flag
case 1 % upper bound
total_count=count*len; count=0;
for i=1:n
for j=1:n
bg_color=get(handle(n*(i-1)+j),'Backgroundcolor');
if ~all(bg_color==[1 1 1])
if i==j
Tune_flag(i)=i;
end
freq=Xwc_ub_w{i,j}(:,2)';
for k=1:length(freq)
if any(Xwc_ub_w{i,j}(k,3:end)~=0)
x=Xwc_ub_w{i,j}(k,3:end);
end
[x,fval]=fmincon(fun,x,[],[],[],[],vlb,vub,constn,option,...
y,Epsilon,-1,freq(k),ps,ms,qs,order,i,j,input_delay,pds,qds);
Xwc_ub_w{i,j}(k,3:end)=x;
Xwc_ub_w{i,j}(k,1)=-fval;
count=count+1;
waitbar(count/total_count,h_wait);
end
end
end
end
close(h_wait)
figure(f);
for i=1:n
for j=1:n
bg_color=get(handle(n*(i-1)+j),'Backgroundcolor');
if ~all(bg_color==[1 1 1])
g=loglog(Xwc_ub_w{i,j}(:,2),Xwc_ub_w{i,j}(:,1),'-');
set(g,'color',bg_color);
set(g,'ButtonDownFcn',['temp=get(gca,''CurrentPoint'');temp=text(temp(1,1),temp(2,2),',...
'[''Mp='' num2str(max(get(gco,''Ydata'')))],''color'',[' num2str(bg_color) ']);']);
hold on
disp(' ');
disp(' ');
disp(['Upper bound results for the (' num2str(i) ' , ' num2str(j) ') component :']);
disp('Mag Freq | ---> Uncertain parameters x(i) ');
print_result(Xwc_ub_w{i,j});
if i==j
g=loglog(10.^decade,[Mp(i) Mp(i)],'-.');
set(g,'color',bg_color);
h=text(mean(10.^decade)/2,Mp(i),['Mp = ' num2str(Mp(i))]);
set(h,'color',bg_color,'VerticalAlignment','bottom');
end
end
end
end
axis auto
temp=axis;
set(L_handle(2),'string',num2str(temp(3)));
set(L_handle(1),'string',num2str(temp(4)));
title('Upper bound of the frequency response');
xlabel('Frequency');
ylabel('Magnitude');
case 2 % lower bound
total_count=count*len; count=0;
for i=1:n
for j=1:n
bg_color=get(handle(n*(i-1)+j),'Backgroundcolor');
if ~all(bg_color==[1 1 1])
freq=Xwc_lb_w{i,j}(:,2)';
for k=1:length(freq)
if any(Xwc_lb_w{i,j}(k,3:end)~=0)
x=Xwc_lb_w{i,j}(k,3:end);
end
[x,fval]=fmincon(fun,x,[],[],[],[],vlb,vub,[],option,...
y,Epsilon,1,freq(k),ps,ms,qs,order,i,j,input_delay,pds,qds);
Xwc_lb_w{i,j}(k,3:end)=x;
Xwc_lb_w{i,j}(k,1)=fval;
count=count+1;
waitbar(count/total_count,h_wait);
end
end
end
end
close(h_wait)
figure(f);
for i=1:n
for j=1:n
bg_color=get(handle(n*(i-1)+j),'Backgroundcolor');
if ~all(bg_color==[1 1 1])
g=loglog(Xwc_lb_w{i,j}(:,2),Xwc_lb_w{i,j}(:,1),'--');
set(g,'color',bg_color);
hold on
disp(' ');
disp(' ');
disp(['Lower bound results for the (' num2str(i) ' , ' num2str(j) ') component :']);
disp('Mag Freq | ---> Uncertain parameters x(i) ');
print_result(Xwc_lb_w{i,j});
end
end
end
axis auto
temp=axis;
set(L_handle(2),'string',num2str(temp(3)));
set(L_handle(1),'string',num2str(temp(4)));
title('Lower bound of the frequency response');
xlabel('Frequency');
ylabel('Magnitude');
case 3 % both upper and lower bound
total_count=count*len*2; count=0;
for i=1:n
for j=1:n
bg_color=get(handle(n*(i-1)+j),'Backgroundcolor');
if ~all(bg_color==[1 1 1])
if i==j
Tune_flag(i)=i;
end
freq=Xwc_ub_w{i,j}(:,2)';
for k=1:length(freq)
if any(Xwc_ub_w{i,j}(k,3:end)~=0)
x=Xwc_ub_w{i,j}(k,3:end);
end
[x,fval]=fmincon(fun,x,[],[],[],[],vlb,vub,constn,option,...
y,Epsilon,-1,freq(k),ps,ms,qs,order,i,j,input_delay,pds,qds);
Xwc_ub_w{i,j}(k,3:end)=x;
Xwc_ub_w{i,j}(k,1)=-fval;
count=count+1;
waitbar(count/total_count,h_wait);
end
end
end
end
% close(h_wait)
for i=1:n
for j=1:n
bg_color=get(handle(n*(i-1)+j),'Backgroundcolor');
if ~all(bg_color==[1 1 1])
freq=Xwc_lb_w{i,j}(:,2)';
for k=1:length(freq)
if any(Xwc_lb_w{i,j}(k,3:end)~=0)
x=Xwc_lb_w{i,j}(k,3:end);
end
[x,fval]=fmincon(fun,x,[],[],[],[],vlb,vub,[],option,...
y,Epsilon,1,freq(k),ps,ms,qs,order,i,j,input_delay,pds,qds);
Xwc_lb_w{i,j}(k,3:end)=x;
Xwc_lb_w{i,j}(k,1)=fval;
count=count+1;
waitbar(count/total_count,h_wait);
end
end
end
end
close(h_wait)
figure(f);
for i=1:n
for j=1:n
bg_color=get(handle(n*(i-1)+j),'Backgroundcolor');
if ~all(bg_color==[1 1 1])
g=loglog(Xwc_ub_w{i,j}(:,2),Xwc_ub_w{i,j}(:,1),'-');
set(g,'color',bg_color);
hold on
disp(' ');
disp(' ');
disp(['Upper bound results for the (' num2str(i) ' , ' num2str(j) ') component :']);
disp('Mag Freq | ---> Uncertain parameters x(i) ');
print_result(Xwc_ub_w{i,j});
h=loglog(Xwc_lb_w{i,j}(:,2),Xwc_lb_w{i,j}(:,1),'--');
set(h,'color',bg_color);
disp(' ');
disp(' ');
disp(['Lower bound results for the (' num2str(i) ' , ' num2str(j) ') component :']);
disp('Mag Freq | ---> Uncertain parameters x(i) ');
print_result(Xwc_lb_w{i,j});
end
end
end
axis auto
temp=axis;
set(L_handle(2),'string',num2str(temp(3)));
set(L_handle(1),'string',num2str(temp(4)));
title('Upper & lower bound of the frequency response');
xlabel('Frequency');
ylabel('Magnitude');
end
toc
function print_result(X)
[m,n]=size(X);
for i=1:m
fprintf('%g ',X(i,:));
fprintf('\n');
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -