Trying to code a state space modelling for thrust vector control of a rocket. I keep getting Error using plot, Invalid Data Argument, please help
6 views (last 30 days)
Show older comments
%% STATE SPACE MODELLING %%1%
clc;
close all;
clear all;
%-cosntant values
Iyy=2.186e8;
m=38901;
Tc=2.361e6;
v= 1347;
Cn_alpha=0.1465;
g= 26.10;
N_alpha=686819;
M_alpha=0.3807;
M_delta=0.5726;
x_cg=53.19;
x_cp=121.2;
F=Tc;
%Othr important constants
Mach=1.4 %mach
h=34000; %height of the launch
S=116.2,7 %Area of the platform
Fbase=1000; %base drag
Ca=2.4; %coefficients
D=Ca*680*3-Fbase; %-drag
Drag=7.15*D %total drag
%state space matrix
A_m=[0 1 0;M_alpha 0 M_alpha/v;-(F-Drag+N_alpha)/m 0 -N_alpha/(m*v)];
B_m=[0;M_delta;Tc/m];
C_m=diag([1 1 1])
D_m=[0; 0; 0]
pitch_ss= ss(A_m, B_m,C_m, D_m);
%%% COST FUNCTION %%%
%cost function
cvector={'bo' 'ro' 'go'};
R_vector=[ 0.1 5 10]
%lowest weight to TVC angle, max to drift
figure;hold on;
for k=1:1
R_matrix_drift=R_vector(k);
Q_matrix_drift=[1 0 1/v; 0 0 0;1/v 0 1/v^2];
[K S e] = lqr(pitch_ss,Q_matrix_drift,R_matrix_drift);
for i=1:10000
e_val( :,i ) =eig (A_m-B_m*K*i/10000);
end
plot(real(e_val(1,:)),imag(e_val(1,:)),cvector(k));
plot(real(e_val(2,:)),imag(e_val(2,:)),cvector(k));
plot(real(eval(3,:)),imag(e_val(3,:)),cvector(k));
grid;
end
xlim([-2 1]);
legend ('R=0.1') ;
%LQR Gains are obtained
K_1=K(1);
K_2=K(2);
K_3=K(3);
0 Comments
Answers (2)
Walter Roberson
on 25 Jul 2022
cvector{k} not (k). You cannot pass a cell array into plot, you have to dereference it
1 Comment
Sam Chak
on 26 Jul 2022
@Chinmay Kundapur, alternatively, you can directly write the color code straightaway.
Iyy = 2.186e8;
m = 38901;
Tc = 2.361e6;
v = 1347;
Cn_alpha = 0.1465;
g = 26.10;
N_alpha = 686819;
M_alpha = 0.3807;
M_delta = 0.5726;
x_cg = 53.19;
x_cp = 121.2;
F = Tc;
% Oth(e)r important constants
Mach = 1.4; %mach
h = 34000; %height of the launch
S = 116.27; %Area of the platform
Fbase = 1000; %base drag
Ca = 2.4; %coefficients
D = Ca*680*3-Fbase; %-drag
Drag = 7.15*D; %total drag
% state space matrix
A_m = [0 1 0; M_alpha 0 M_alpha/v; -(F-Drag+N_alpha)/m 0 -N_alpha/(m*v)];
B_m = [0; M_delta; Tc/m];
C_m = diag([1 1 1]);
D_m = [0; 0; 0];
pitch_ss = ss(A_m, B_m, C_m, D_m)
R_vector = [0.1 5 10];
% lowest weight to TVC angle, max to drift
figure; hold on;
for k = 1:1
R_matrix_drift = R_vector(k);
Q_matrix_drift = [1 0 1/v; 0 0 0; 1/v 0 1/v^2];
[K S e] = lqr(pitch_ss, Q_matrix_drift, R_matrix_drift);
for i = 1:10000
e_val( :,i ) = eig (A_m-B_m*K*i/10000);
end
plot(real(e_val(1,:)),imag(e_val(1,:)), 'bo');
plot(real(e_val(2,:)),imag(e_val(2,:)), 'ro');
plot(real(e_val(3,:)),imag(e_val(3,:)), 'go');
grid;
end
xlim([-2 1]);
legend ('R=0.1');
%LQR Gains are obtained
K_1 = K(1)
K_2 = K(2)
K_3 = K(3)
0 Comments
See Also
Categories
Find more on Computational Geometry in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!