Introduce step signal after system response

조회 수: 2 (최근 30일)
mikel lasa
mikel lasa 2022년 7월 19일
댓글: mikel lasa 2022년 7월 21일
Hello,
sorry for the summary, I dont know how to resume my question in few words.
I have a second order system which I know how will respond without an input signal, like this:
x1'=x2;
x2'=ax1+bx2
using ODE 45 and I get this response
where the position (x1) acts like this
now I need to insert a step signal "u" at second 20. The system looks like this but I dont know how to do it. I have created this signal as a vector but I'm getting an error in the ODE 45 function. How can I introduce u into the equation in order to alterate this system in the second 20?
x1'=x2;
x2'=ax1+bx2 + u
this is my code so far:
%% INIT
clear variables;
close all;
clc;
%% Reference input
%STEP
t = (1:1:60)'; % entering U as a vector is not working
u=t>=20;
% figure()
% plot(t,u)
%% variable initialization
%coefs
a=-0.3;
b=-1.1;
%gains
% Kp=3;
% Ki=0.9;
% Kd=0.8;
%initial conditions
x1init= 2.5;
x2init= 2.5;
% time
time=100;
%% Space state equation
%define second order equation system
f = @(t,X) [X(2); a*X(1)+b*X(2)+u];
% define the area where the function will be analysed
[x1,x2] = meshgrid(-5:5);
x1mat = zeros(size(x1));
x2mat = zeros(size(x2));
%
t=0;
for i = 1:numel(x1)
Xprima = f(t,[x1(i); x2(i)]);
x1mat(i) = Xprima(1);
x2mat(i) = Xprima(2);
end
%% PLOT THE AREA
figure
quiver(x1,x2,x1mat,x2mat,'r'); figure(gcf)
xlabel('x1')
ylabel('x2')
axis tight equal;
title('Phase diagram ')
hold on
%% PLOT FUNCTION SOLUTION
%
%options=odeset('InitialStep',1e-3,'MaxStep',100);
for sol1 = [x1init ; x2init]
[ts,ys] = ode45(f,[0,time],sol1);
plot(ys(:,1),ys(:,2),'r')
plot(ys(1,1),ys(1,2),'bo') % starting point
plot(ys(end,1),ys(end,2),'ks') % ending point
end
hold off
figure
subplot(2,1,1)
plot(ts,ys(:,1),'k', 'LineWidth',2)
xlabel('time(s)','fontweight','bold','FontSize',12)
ylabel('position','fontweight','bold','FontSize',12)
subplot(2,1,2)
plot(ts,ys(:,2),'k', 'LineWidth',2)
xlabel('time(s)','fontweight','bold','FontSize',12)
ylabel('speed','fontweight','bold','FontSize',12)
title('function evolution')

채택된 답변

Paul
Paul 2022년 7월 19일
Hi mikel,
No need to use ode45 for this particular problem. The delayed step response with initial conditions can be obtained as
a=-0.3;
b=-1.1;
sys = ss([0 1;a b],[0;1],eye(2),0);
%initial conditions
x1init= 2.5;
x2init= 2.5;
% time
time=100;
ts = 0:.1:time; % small time step, make sure a point in ts hits 20
ys = initial(sys,[x1init x2init],ts) + step(sys*tf(1,1,'InputDelay',20),ts);
% or use lsim
%ys = lsim(sys,ts>=20,ts,[x1init x2init]);
figure
subplot(2,1,1)
plot(ts,ys(:,1),'k', 'LineWidth',2)
xlabel('time(s)','fontweight','bold','FontSize',12)
ylabel('position','fontweight','bold','FontSize',12)
subplot(2,1,2)
plot(ts,ys(:,2),'k', 'LineWidth',2)
xlabel('time(s)','fontweight','bold','FontSize',12)
ylabel('speed','fontweight','bold','FontSize',12)
title('function evolution')
  댓글 수: 3
Paul
Paul 2022년 7월 20일
편집: Paul 2022년 7월 20일
initial computes the response of a state space system to initial conditions on the state variables with zero input. I'm not sure I can describe it any differently than the doc page. Note that in the state space model sys I selected C as eye(2) so that the outputs of sys are the state variables.
To explore the response to different inputs, lsim is most likely the way to go (see commented line above) with apprropriate selection of the "method" argument, except for an impulse input which would have to be handled as a special case with lsim.
mikel lasa
mikel lasa 2022년 7월 21일
thank you! understood!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by