
I want to generate a lateral speed plot with range of forward speeds
    2 views (last 30 days)
  
       Show older comments
    
This code generates lateral speed plot with constant forward speed u=20 but i want to generate a plot with variable forward speeds. u [5,35] to be exact. I tried to change the u to a variable but it didn't work.
a = 1.34; 
L = 2.851; 
m = 2425; 
Iz = 2700.0;
Caf = 1900; 
Car = 2000;
b=L-a; g=9.81;
Kus = m*b/(L*Caf) - m*a/(L*Car); 
u=20.0; 
A=[-(Caf+Car)/(m*u), (b*Car-a*Caf)/(m*u)-u
(b*Car-a*Caf)/(Iz*u), -(a^2*Caf+b^2*Car)/(Iz*u)];
B=[Caf/m; a*Caf/Iz];
C_lat = [1 0]; D_lat = 0; % Lateral speed
C = [C_lat;];
D = [D_lat;];
t=[0:0.01:10];
U=10*pi/180*sin(1/3*2*pi*t);
Y=lsim(A,B,C,D,U,t);
subplot, subplot(221)
plot(t,Y(:,1),'r'); grid
xlabel('time (sec)')
ylabel('Lateral speed (m/sec)')
0 Comments
Accepted Answer
  Mathieu NOE
      
 on 7 Nov 2022
        hello 
you can do a for loop 

a = 1.34; 
L = 2.851; 
m = 2425; 
Iz = 2700.0;
Caf = 1900; 
Car = 2000;
b=L-a; g=9.81;
Kus = m*b/(L*Caf) - m*a/(L*Car); 
% u=20.0; 
u=(5:5:35); 
t=[0:0.01:10];
U=10*pi/180*sin(1/3*2*pi*t);
Yall = [];
for ci =1:numel(u)
    A=[-(Caf+Car)/(m*u(ci)), (b*Car-a*Caf)/(m*u(ci))-u(ci)
    (b*Car-a*Caf)/(Iz*u(ci)), -(a^2*Caf+b^2*Car)/(Iz*u(ci))];
    B=[Caf/m; a*Caf/Iz];
    C_lat = [1 0]; D_lat = 0; % Lateral speed
    C = [C_lat;];
    D = [D_lat;];
    Y=lsim(A,B,C,D,U,t);
    Yall = [Yall Y];
    leg{ci} = [' u = ' num2str(u(ci))]; % legend char array
end
    plot(t,Yall); grid
    title('Lateral speed')
    xlabel('time (sec)')
    ylabel('(m/sec)')
    legend(leg);
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
