Getting multiple outputs using lqr function
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I've got the following matrices, and want to design a LQR controller-
A=[-0.0507 -3.861 0 -32.17; -1.17e-3 -0.5164 1 0;-1.29e-4 1.4168 -0.4932 0;0 0 1 0];
B=[0 -0.0717 -0.1645 0]';
C=[0 0 0 1];
Q=diag([1e-3 1e-2 1 1e-3]);
R=1;
To get the controller parameters-
[K,S,e]=lqr(A,B,Q,R);
I now want to show the effect of using different values of R and plot things, say the value of the gain. I know this can be done using a for loop. However, I understand that Matlab's for loop should probably be avoided as much as possible, and so was wondering, is there a vector method of doing this?
Thanks in advance!
0 Kommentare
Antworten (1)
Star Strider
am 26 Jan. 2018
There is no reason to avoid explicit loops. Many MATLAB functions have very efficient implicit loops, so they are preferred over explicit loops.
If you want to avoid an explicit loop, you can use arrayfun. I have not timed the difference between a for loop and arrayfun to see which is faster or more efficient.
Try this:
[Kc,Sc,ec] = arrayfun(@(R) lqr(A,B,Q,R), 1:5, 'Uni',false);
This iterates through ‘R=[1:5]’, and outputs to the cell arrays.
Experiment to get the result you want.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!