Getting Both Symbolic Output and Numeric Output
Afficher commentaires plus anciens
I would like to generate symbolic expressions representing the computations involved in a snippet of code (shown below), while simultaneously computing the actual numeric values used to solve the problem.
Let's say A is a 2x2 matrix, B is a 1x2 vector, Q is a 2x2 matrix, and R is a 1x1:
b = 100;
m = 1500;
A = [0 1; 0 -b/m];
B = [0 1/m]';
Q = 2*eye(length(A));
R = 2*eye(size(B,2));
I would like both the numeric solution for K, and the symoblic expressions representing the solution to K. For example,
K = [0 , -0.0125] and
K = [- A11*((B11*Q11)/(R11 + B11*(B11*Q11 + B21*Q21) + B21*(B11*Q12 + B21*Q22)) ...., - A12*((B11*Q11)/(R11 + B11*(B11*Q11 + B21*Q21) + B21*(B11*Q12 + B21*Q22)) ...]
function [ K ] = dlqr_finite( A, B, Q, R, N )
P = cell(1, N);
K = cell(1, N);
P{N+1} = Q;
% Solve backwards in time from N to 0
n = N+1;
while n > 1
P{n-1} = Q + (A.'*P{n}*A) - (A.'*P{n}*B)*(R+B.'*P{n}*B)^-1*(B.'*P{n}*A);
K{n-1} = -1*(R+B.'*P{n}*B)^-1*(B.'*P{n}*A);
n = n-1;
end
end
What is the easiest way to achieve these simultaneously?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Common Operations dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!