ナイーブなフィードバック制御

clear all; close;

function prettify()
    a = gca();                                            // Active le handle "Axes"
    a.font_size = 5;   
    a.thickness = 2;
    a.children.children(1).thickness = 5;
    a.data_bounds(:,2)=[-0.3;0.3]; //Y軸の範囲を 0〜2に
endfunction

function y2=addNoise(y)        
 y2 = y + grand(1,length(y),"nor",0,0.01)
endfunction


maxT=10;
Nt=101;
t = linspace(0,maxT,Nt);
y = -0.01*t;
plot(t,y);
prettify();
title('Feedback control using LQR regulator','fontsize',7);
set(gca(),"auto_clear","off")

y2 = addNoise(y);
plot(t,y2,'r-');

deltaT=1;
current_regulation=0;
for idx=1:Nt
    ti=t(idx);
    sensored_y = -0.01*ti;
    if (modulo(ti,deltaT)==0) then
        y3(idx) = -0.01*ti - sensored_y;
        current_regulation = sensored_y;
    else 
        y3(idx) = -0.01*ti - current_regulation;
    end
end
plot(t,y3,'g-');


for idx=1:Nt
    ti=t(idx);
    sensored_y = -0.01*ti + grand(1,1,"nor",0,0.01);
    if (modulo(ti,deltaT)==0) then
        y4(idx) = -0.01*ti - sensored_y;
        current_regulation = sensored_y;
    else 
        y4(idx) = -0.01*ti - current_regulation;
    end
end

plot(t,y4,'c-');

legend(['ideal','Gaussian noise','naive feedback for ideal','naive feedback for gaussian noise']);