Cost function to minimize variance of error
2 views (last 30 days)
Show older comments
I need to design a cost function to minimize the variance of error input to my controller in order to find out optimum values of my controller parameters. I have the transfer function of my plant and my reference signal is a constant 0. My controller is a simple lead lag filter with a gain. How do I design a cost function for this task?
0 Comments
Answers (1)
Sam Chak
on 31 Oct 2022
Since you didn't provide info about your system. here is an example that you can study. However, I don't think that miniming the error variance works.
In the example, if you let , then the variance .
k0 = 1;
k = fminunc(@costfun, k0)
s = tf('s');
Gp = 1/(s*(s + 5)*(s + 10));
Gc = k*((s + 4)*(s + 0.1))/((s + 7.3)*(s + 0.01));
Gcl = feedback(Gc*Gp, 1);
t = linspace(0, 10, 1001);
step(Gcl, t)
function J = costfun(k)
s = tf('s');
Gp = 1/(s*(s + 5)*(s + 10));
Gc = k*((s + 4)*(s + 0.1))/((s + 7.3)*(s + 0.01));
Gcl = feedback(Gc*Gp, 1);
t = linspace(0, 10, 1001);
y = step(Gcl, t);
err = 1 - y;
% J = var(err);
J = trapz(t, err.^2);
end
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!