Switched system dependent on time
조회 수: 5 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
Abhishek Chakram
2023년 11월 9일
편집: Abhishek Chakram
2023년 11월 9일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 General Applications에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
