Getting multiple outputs using lqr function
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Star Strider
2018-1-26
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!