Help! I'm having trouble plotting hamiltonian and LQR.
8 次查看(过去 30 天)
显示 更早的评论
Hi,
I'm attempting to land a rocket using state space equations. I'm using optimal controls LQR and Hamiltonian. I have an example of a smaller matrix attached but I can't seem to get Matlab code enough to expand it to the dimensions of my Matrix.
Please help! Here is my code:
clc, clear all, close all
syms u(t) x(t) x1 x2 x3 x4 x5 x6 u1 u2 u3 lambda1 lambda2 lambda3 lambda4 lambda5 lambda6 lambda Q R
Q = eye(6);
R = 5;
x0 = [241500 0].';
t0 = 0;
tf = 5;
l1=35; % meters
l2=35;% meters
ln=1; % 1 meter nozzle length
m=30000; %kg, mass of the rocket
J=m*(l1+l2)^2/12; %moment of inertia
g=9.5; %m/s
theta = pi;
phi = pi/12;
Fe=64860; %Newtons
Fs=130;%Newtons
N=0;
F=eye();
u=[Fe theta phi].';
x=[x1 x2 x3 x4 x5 x6].';
A = [0 0 0 1 0 0; 0 0 0 0 1 0; 0 0 0 0 0 1; 0 0 g 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0]
B = [0 0 0; 0 0 0; 0 0 0; theta/m 1 m*g; theta/m -m -g*theta; 1-phi*(l1+ln)/J l2/J -Fe*(l1+ln)/J]
% A_transpose = A.';
% B_transpose = B.';
% %ode1 = diff(x_dot) == A_transpose*x + B_transpose*u;
H=0.5*x.'*Q*x+.5*u.'*R*u+lambda1.'*A*x+ lambda2.'*B*u; %Hamiltonian Function
[K,S,P] = lqr(A,B,Q,R,N)
0 个评论
回答(6 个)
Pavel Osipov
2019-11-7
Damian Prashad, good afternoon. Looked up Your code. Everything works well. What matrices Would you like to change to larger sizes? Where do difficulties arise? You are probably hampered by the loss of precision in matrix transformations whose elements differ by 10^11 times (B). This may well lead to a loss of computational stability.
All the best, Paul.
Pavel Osipov
2019-11-8
Damian, Hello! Putting matrices C =diag(1,...,1) and D=zeros(.,.) get Your system of equations. Simulink State-Space block allows you to solve linear control problems without much hassle. I can send a training file where the problem of oscillations of a double spring pendulum is solved by Simulink. Matrix A: Size [4x4]. I hope You solve Your problem by analogy. Simulink also has nonlinear blocks x'=f (x, u, t) to solve your control. While there is little free time to learn more about your script. Don't take offense at me. Advice is much easier to give than to program.
Sincerely Yours, Pavel Osipov.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!