Symbolic Solutions That Populate a Vector
5 ビュー (過去 30 日間)
古いコメントを表示
I am trying to approximate a solution to the Riccati equation. To do this, I have a final value and work backwards to obtain all previous values. The issue is that in this particular case the solution needs to be symbolic bexause it depends on a function of time that will be calculated later. The code I came up with is listed below. This works very well when there is no symbolic variable to deal with.
% P(tf)
P_11(length(t)) = F(1,1);
P_12(length(t)) = F(1,2);
P_22(length(t)) = F(2,2);
% Solve Riccati eqn backwards
syms z;
for n=length(t) : -1 : 2
P_11_dot = P_12(n)^2 + 3*z*P_12(n) + 3*P_12(n)*z - 1;
P_12_dot = 2*P_12(n) - P_11(n) + P_12(n)*P_22(n) + 3*P_22(n)*z;
P_22_dot = 4*P_22(n) - 2*P_12(n) + P_22(n)^2;
P_11(n-1) = P_11(n) - P_11_dot*step;
P_12(n-1) = P_12(n) - P_12_dot*step;
P_22(n-1) = P_22(n) - P_22_dot*step;
end
the error message i get is this;
The following error occurred converting from sym to double:
Unable to convert expression into double array.
Error in LTV_SYS (line 56)
P_11(n-1) = P_11(n) - P_11_dot*step;
The idea is to then calculate z using the code below. Here, I know the initial conditions and since my symbolic variable (z) is a state, I should be able to substitute in for it. The problem is I can't get to this point because of the above error.
% Initialize state vector
x(:,1) = x0;
% Solve for optimal state and control
for n=1 : length(t)-1
z = x(1,n);
A = [0 1; -3*z -2];
P = [P_11(n) P_12(n); P_12(n) P_22(n)];
K(n,:) = inv(R)*B'*P;
U(n+1) = -K(n,:)*x(:,n);
x_dot = A*x(:,n)+B*U(n+1);
x(:,n+1) = x(:,n) + x_dot*step;
end
I appreciate any help that anyone can offer.
0 件のコメント
回答 (1 件)
Walter Roberson
2020 年 3 月 11 日
P_11(length(t)) = sym(F(1,1));
P_12(length(t)) = sym(F(1,2));
P_22(length(t)) = sym(F(2,2));
7 件のコメント
Walter Roberson
2020 年 3 月 11 日
"You can use digits() to control the precision you want to execute to."
参考
カテゴリ
Help Center および File Exchange で Number Theory についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!