can dde23 be used for varying time delays

6 visualizaciones (últimos 30 días)
Pallov Anand
Pallov Anand el 1 de Abr. de 2025
Editada: Walter Roberson el 1 de Abr. de 2025
I have the following code. The expression for u which contains y1_tau2, x1_tau1, y2_tau2, x2_tau1 etc are all delayed signals but with constant delays. I want to make it variable delays like following:
y1_tau2 should be y1(t - \tau_2_hat)
similarly, x2_tau1 should be x2(t - \tau1_hat)
and then I would define the error between the actual and the estimates, for e.g:
And further I can have some dynamics for \dot{\tilde{\tau_1}} and \dot{\tilde{\tau_2}}
So, can it be done using dde23? If not, how can i dot it?
clc;
clear;
close all;
% Define Parameters
a = 1.2;
b = 2.92;
c = 6;
ita = 0.8; % Constant
% Define Time Span
tspan = [0, 30]; % Simulation time span
% Initial delay estimates
tau_initial = [0.02; 0.02]; % Initial guesses for tau1_hat and tau2_hat
% Call the DDE Solver
sol = dde23(@system_dynamics, tau_initial, @delay_function, tspan);
% Extract solutions
t_values = sol.x;
x1_values = sol.y(1, :);
x2_values = sol.y(2, :);
x3_values = sol.y(3, :);
y1_values = sol.y(4, :);
y2_values = sol.y(5, :);
y3_values = sol.y(6, :);
% Compute control input u at each time step
u_values = zeros(size(t_values));
for i = 1:length(t_values)
x1_tau1 = interp1(t_values, x1_values, max(0, t_values(i) - tau_initial(1)), 'previous', 'extrap');
x2_tau1 = interp1(t_values, x2_values, max(0, t_values(i) - tau_initial(1)), 'previous', 'extrap');
x3_tau1 = interp1(t_values, x3_values, max(0, t_values(i) - tau_initial(1)), 'previous', 'extrap');
y1_tau2 = interp1(t_values, y1_values, max(0, t_values(i) - tau_initial(2)), 'previous', 'extrap');
y2_tau2 = interp1(t_values, y2_values, max(0, t_values(i) - tau_initial(2)), 'previous', 'extrap');
y3_tau2 = interp1(t_values, y3_values, max(0, t_values(i) - tau_initial(2)), 'previous', 'extrap');
% Compute errors
e1 = y1_values(i) - x1_values(i);
e2 = y2_values(i) - x2_values(i);
e3 = y3_values(i) - x3_values(i);
% Finite-time control terms
alpha1 = -e1^ita;
z1 = e2 - alpha1;
alpha1_dot = -ita * e1^(ita-1) * e2;
alpha2 = alpha1_dot - e1 - z1^ita;
z2 = e3 - alpha2;
alpha1_d_dot = -ita * (e1^(ita-1)*e3 + (ita-1) * e1^(ita-2) * e2^2);
alpha2_dot = alpha1_d_dot - e2 - ita * z1^(ita-1) * (-e1 + z2 - z1^ita);
% Control input u
u_values(i) = c * (y1_tau2 - x1_tau1) + ...
b * (y2_tau2 - x2_tau1) + ...
a * (y3_tau2 - x3_tau1) - ...
y1_values(i)^2 + x1_values(i)^2 + alpha2_dot - z1 - z2^(ita) * sign(z2);
end
% Plot x1 vs y1
figure;
plot(t_values, x1_values, 'r', 'LineWidth', 1.5); hold on;
plot(t_values, y1_values, 'b', 'LineWidth', 1.5);
xlabel('Time');
ylabel('State Variables');
legend('Master System x_1', 'Slave System y_1');
title('Time Evolution of x_1 and y_1');
grid on;
% Plot x2 vs y2
figure;
plot(t_values, x2_values, 'r', 'LineWidth', 1.5); hold on;
plot(t_values, y2_values, 'b', 'LineWidth', 1.5);
xlabel('Time');
ylabel('State Variables');
legend('Master System x_2', 'Slave System y_2');
title('Time Evolution of x_2 and y_2');
grid on;
% Plot x3 vs y3
figure;
plot(t_values, x3_values, 'r', 'LineWidth', 1.5); hold on;
plot(t_values, y3_values, 'b', 'LineWidth', 1.5);
xlabel('Time');
ylabel('State Variables');
legend('Master System x_3', 'Slave System y_3');
title('Time Evolution of x_3 and y_3');
grid on;
% Plot control input u over time
figure;
plot(t_values, u_values, 'k', 'LineWidth', 1.5);
xlabel('Time');
ylabel('Control Input u');
title('Control Input u over Time');
grid on;
%% ================= System Dynamics Function ==================
function dydt = system_dynamics(t, y, Z)
% Extract state variables
x1 = y(1); x2 = y(2); x3 = y(3);
y1 = y(4); y2 = y(5); y3 = y(6);
% Delayed states from dde23
x1_tau1 = Z(1, 1); % x1 delayed by tau1
x2_tau1 = Z(2, 1); % x2 delayed by tau1
x3_tau1 = Z(3, 1); % x3 delayed by tau1
y1_tau2 = Z(4, 2); % y1 delayed by tau2
y2_tau2 = Z(5, 2); % y2 delayed by tau2
y3_tau2 = Z(6, 2); % y3 delayed by tau2
% Compute errors
e1 = y1 - x1;
e2 = y2 - x2;
e3 = y3 - x3;
% Finite-time control laws
ita = 0.8;
alpha1 = -e1^ita;
z1 = e2 - alpha1;
alpha1_dot = -ita * e1^(ita-1) * e2;
alpha2 = alpha1_dot - e1 - z1^ita;
z2 = e3 - alpha2;
alpha1_d_dot = -ita * (e1^(ita-1)*e3 + (ita-1) * e1^(ita-2) * e2^2);
alpha2_dot = alpha1_d_dot - e2 - ita * z1^(ita-1) * (-e1 + z2 - z1^ita);
a = 1.2;
b = 2.92;
c = 6;
% Control input u
u = c * (y1_tau2 - x1_tau1) + ...
b * (y2_tau2 - x2_tau1) + ...
a * (y3_tau2 - x3_tau1) - ...
y1^2 + x1^2 + alpha2_dot - z1 - z2^(ita) * sign(z2);
% System equations (master and slave systems)
dydt = zeros(6,1);
dydt(1) = x2;
dydt(2) = x3;
dydt(3) = -c*x1_tau1 - b*x2_tau1 - a*x3_tau1 + x1^2; % Master System
dydt(4) = y2;
dydt(5) = y3;
dydt(6) = -c*y1_tau2 - b*y2_tau2 - a*y3_tau2 + y1^2 + u; % Slave System
end
% ================= Delay Function ==================
function y0 = delay_function(t)
if t == 0
y0 = [2; -1; 3; % Master system initial conditions
0; 0; 0]; % Slave system initial conditions
else
y0 = zeros(6, 1);
end
end

Respuesta aceptada

Jack
Jack el 1 de Abr. de 2025
dde23 only supports constant delays. If you want to use time‐varying (or state‐dependent) delays—such as delays that change over time or depend on the system state—you’ll need to use MATLAB’s ddesd solver, which is specifically designed for state-dependent delay differential equations.
Follow me so you can message me anytime with future questions. If this helps, please accept the answer and upvote it as well.

Más respuestas (0)

Categorías

Más información sobre Biotech and Pharmaceutical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by