Switched system dependent on time

3 visualizaciones (últimos 30 días)
Muhammad Qureshi
Muhammad Qureshi el 18 de Feb. de 2022
Editada: Abhishek Chakram el 9 de Nov. de 2023
Hello,
I am trying to model a switched dynamic system in matlab. So say for the initial .4sec, x is given by the solution of sysA, xdot = Ax. But, after t = .4 sec to t = 1sec, x is now the soln of sysB, xdot = Bx. But the output of sysB should start where the output of sys A ends and vice versa. And then at t = 1sec to 1.4 sec, output of sys is again given by xdot = Ax.
I have tried to implement it in simulink as well as in matlab using ODE functions but have been unsucessful. Do you guys have any idea on how to go about it?
(For those that know how DC converter modelling works, I am esentially trying to model a boost converter system but without using the duty cycle D as a variable in the system).
Thank you.

Respuestas (1)

Abhishek Chakram
Abhishek Chakram el 9 de Nov. de 2023
Editada: Abhishek Chakram el 9 de Nov. de 2023
Hi Muhammad Qureshi,
It seems to me that you are having trouble switching between systems based on the time. Making a custom function that modifies the "xdot" in response to time can serve as one of the probable methods to achieve this. Here is a sample code for the same:
% Define the system matrices A and B
A = [1 2; 3 4]; % Replace with your own matrices
B = [5 6; 7 8]; % Replace with your own matrices
% Set initial conditions and time span
x0 = [1 1]; % Replace with your own initial conditions
totaltime = 5; % total seconds
t = [];
x = [];
% Solve the differential equations for each time interval
for i= 0:totaltime
[t1, x1] = ode45(@(t, x) systemODE(t, x, A, B), [i i+0.4], x0(end, :)');
[t2, x2] = ode45(@(t, x) systemODE(t, x, A, B), [i+0.4 i+1], x1(end, :)');
x0 = x2;
x = [x; x1; x2];
t= [t; t1; t2];
end
% Plot the results
plot(t, x);
xlabel('Time');
ylabel('State');
function xdot = systemODE(t, x, A, B)
timeDecimal = t - floor(t);
if timeDecimal >= 0 && timeDecimal < 0.4
xdot = A * x;
elseif timeDecimal >= 0.4 && timeDecimal < 1
xdot = B * x;
end
end
You can refer to the following documentation to know more about the how to create custom functions: https://www.mathworks.com/help/matlab/ref/function.html
Best Regards,
Abhishek Chakram

Categorías

Más información sobre Discrete Events and Mode Charts en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by