Plot of time-trajectories for the synchronization between two systems

I want to ask about plotting the synchronization between two systems b using matlab
here is the code in maple
with(plots);
sys := diff(x(t), t) = a*(-x(t) + y(t)), diff(y(t), t) = b*x(t) - k*x(t)*z(t), diff(z(t), t) = -c*z(t) + h*x(t)^2, diff(X(t), t) = a*(-X(t) + Y(t)) - a*Y(t) + 2*alpha1*a*x(t)*y(t) - alpha1*a*x(t)^2 + a*alpha2*y(t), diff(Y(t), t) = ((b*X(t) - k*X(t)*Z(t)) - b*X(t)) + k*X(t)*Z(t) + 2*beta1*b*x(t)*y(t) - 2*beta1*k*x(t)*y(t)*z(t) + beta2*b*x(t) - beta2*k*x(t)*z(t) - 15*(Y(t) - beta1*y(t)^2 - beta2*y(t)), diff(Z(t), t) = ((-c*Z(t) + h*X(t)^2) - h*X(t)^2) + 2*delta1*h*x(t)^2*z(t) - delta1*c*z(t)^2 + delta2*h*x(t)^2;
NULL;
fcns := {X(t), Y(t), Z(t), x(t), y(t), z(t)};
p := dsolve({sys, X(0) = 20, Y(0) = -3, Z(0) = 16, x(0) = 7, y(0) = -7, z(0) = 5}, fcns, type = numeric);
odeplot(p, [t, X(t) - (alpha1*x(t) + alpha2)*x(t)], 0 .. 6, labels = ['t', 'ex'], color = blue, numpoints = 100, thickness = 2);
p := dsolve({sys, X(0) = 20, Y(0) = -3, Z(0) = 16, x(0) = 7, y(0) = -7, z(0) = 5}, fcns, type = numeric);
odeplot(p, [t, Y(t) - (beta1*y(t) + beta2)*y(t)], 0 .. 8, labels = ['t', 'ey'], color = olive, numpoints = 0.1, thickness = 2);
p := dsolve({sys, X(0) = 20, Y(0) = -3, Z(0) = 16, x(0) = 7, y(0) = -7, z(0) = 5}, fcns, type = numeric);
odeplot(p, [t, Z(t) - (delta1*z(t) + delta2)*z(t)], 0 .. 8, labels = ['t', 'ez'], color = red, numpoints = 0.100, thickness = 2);
p := dsolve({sys, X(0) = 20, Y(0) = -3, Z(0) = 16, x(0) = 7, y(0) = -7, z(0) = 5}, fcns, type = numeric);
odeplot(p, [[t, X(t) - alpha1*x(t)^2 - alpha2*x(t)], [t, Y(t) - (beta1*y(t) + beta2)*y(t)], [t, Z(t) - (delta1*z(t) + delta2)*z(t)]], 0 .. 7, numpoints = 100, color = [blue, olive, red], legend = [e__x, e__y, e__z], thickness = 2);

3 Comments

That Maple code generates the following:
Warning, The use of global variables in numerical ODE problems is deprecated, and will be removed in a future release. Use the 'parameters' argument instead (see ?dsolve,numeric,parameters)
Error, (in plots/odeplot) curve is not fully specified in terms of the ODE solution, found additional unknowns {alpha1, alpha2}
Warning, The use of global variables in numerical ODE problems is deprecated, and will be removed in a future release. Use the 'parameters' argument instead (see ?dsolve,numeric,parameters)
Error, (in plots/odeplot) curve is not fully specified in terms of the ODE solution, found additional unknowns {beta1, beta2}
Warning, The use of global variables in numerical ODE problems is deprecated, and will be removed in a future release. Use the 'parameters' argument instead (see ?dsolve,numeric,parameters)
Error, (in plots/odeplot) curve is not fully specified in terms of the ODE solution, found additional unknowns {delta1, delta2}
Warning, The use of global variables in numerical ODE problems is deprecated, and will be removed in a future release. Use the 'parameters' argument instead (see ?dsolve,numeric,parameters)
Error, (in plots/odeplot) curve 1 is not fully specified in terms of the ODE solution, found additional unknowns {alpha1, alpha2}
In order for that Maple code to produce valid output plots, the symbols alpha1 alpha2 beta1 beta2 delta1 delta2 a b c h k all need to be given numeric values.
here is the values:
a := -10;
b := -4;
c := 18.1;
k11 := 10;
k12 := 3;
k13 := 0;
alpha := -6.335;
beta := 0;
m := 0;

Sign in to comment.

 Accepted Answer

Hey there @Nehad! If you are looking to plot the synchronization between two systems using MATLAB, I have got you covered. Here is a guide to help you translate your Maple code into MATLAB:
  1. Define Your Parameters: First, we need to set up all the constants that we'll use in our equations. Think of these as the settings for your simulation.
  2. Write Down the Equations: We'll use an anonymous function in MATLAB to define our system of differential equations. This function will take time t and a vector Y containing your variables.
  3. Initial Conditions: Let's specify where everything starts. These are the initial values for each of your variables.
  4. Solve the Equations: We'll use ode45, a handy MATLAB function, to solve our system over a specified time span. It's like asking MATLAB to figure out how your system evolves over time.
  5. Calculate the Errors: This is where we see how well the two systems are syncing up by computing the synchronization errors.
  6. Plot the Results: Finally, we'll use MATLAB's plotting capabilities to visualize the errors over time. This will give us a clear picture of how the synchronization is going.
Here's the MATLAB code to do all of that:
% Define your parameters
a = 1; b = 1; c = 1; k = 1; h = 1;
alpha1 = 0.5; alpha2 = 0.5;
beta1 = 0.5; beta2 = 0.5;
delta1 = 0.5; delta2 = 0.5;
% Define the system of differential equations
sys = @(t, Y) [
a * (-Y(1) + Y(2));
b * Y(1) - k * Y(1) * Y(3);
-c * Y(3) + h * Y(1)^2;
a * (-Y(4) + Y(5)) - a * Y(5) + 2 * alpha1 * a * Y(1) * Y(2) - alpha1 * a * Y(1)^2 + a * alpha2 * Y(2);
((b * Y(4) - k * Y(4) * Y(6)) - b * Y(4)) + k * Y(4) * Y(6) + 2 * beta1 * b * Y(1) * Y(2) - 2 * beta1 * k * Y(1) * Y(2) * Y(3) + beta2 * b * Y(1) - beta2 * k * Y(1) * Y(3) - 15 * (Y(5) - beta1 * Y(2)^2 - beta2 * Y(2));
((-c * Y(6) + h * Y(4)^2) - h * Y(4)^2) + 2 * delta1 * h * Y(1)^2 * Y(3) - delta1 * c * Y(3)^2 + delta2 * h * Y(1)^2;
];
% Initial conditions
Y0 = [7, -7, 5, 20, -3, 16];
% Time span
tspan = [0 8];
% Solve the system using ode45
[t, Y] = ode45(sys, tspan, Y0);
% Calculate errors
ex = Y(:, 4) - (alpha1 * Y(:, 1) + alpha2) .* Y(:, 1);
ey = Y(:, 5) - (beta1 * Y(:, 2) + beta2) .* Y(:, 2);
ez = Y(:, 6) - (delta1 * Y(:, 3) + delta2) .* Y(:, 3);
% Plot the results
figure;
plot(t, ex, 'b', 'LineWidth', 2); hold on;
plot(t, ey, 'Color', [0.5, 0.5, 0], 'LineWidth', 2); % olive color
plot(t, ez, 'r', 'LineWidth', 2);
xlabel('t');
ylabel('Errors');
legend('e_x', 'e_y', 'e_z');
title('Synchronization Errors');
grid on;
a = 1; b = 1; c = 1; k = 1; h = 1;
alpha1 = 0.5; alpha2 = 0.5;
beta1 = 0.5; beta2 = 0.5;
delta1 = 0.5; delta2 = 0.5;
% Define the system of differential equations
sys = @(t, Y) [
a * (-Y(1) + Y(2));
b * Y(1) - k * Y(1) * Y(3);
-c * Y(3) + h * Y(1)^2;
a * (-Y(4) + Y(5)) - a * Y(5) + 2 * alpha1 * a * Y(1) * Y(2) - alpha1 * a * Y(1)^2 + a * alpha2 * Y(2);
((b * Y(4) - k * Y(4) * Y(6)) - b * Y(4)) + k * Y(4) * Y(6) + 2 * beta1 * b * Y(1) * Y(2) - 2 * beta1 * k * Y(1) * Y(2) * Y(3) + beta2 * b * Y(1) - beta2 * k * Y(1) * Y(3) - 15 * (Y(5) - beta1 * Y(2)^2 - beta2 * Y(2));
((-c * Y(6) + h * Y(4)^2) - h * Y(4)^2) + 2 * delta1 * h * Y(1)^2 * Y(3) - delta1 * c * Y(3)^2 + delta2 * h * Y(1)^2;
];
% Initial conditions
Y0 = [7, -7, 5, 20, -3, 16];
% Time span
tspan = [0 8];
% Solve the system using ode45
[t, Y] = ode45(sys, tspan, Y0);
% Calculate errors
ex = Y(:, 4) - (alpha1 * Y(:, 1) + alpha2) .* Y(:, 1);
ey = Y(:, 5) - (beta1 * Y(:, 2) + beta2) .* Y(:, 2);
ez = Y(:, 6) - (delta1 * Y(:, 3) + delta2) .* Y(:, 3);
% Plot the results
figure;
plot(t, ex, 'b', 'LineWidth', 2); hold on;
plot(t, ey, 'Color', [0.5, 0.5, 0], 'LineWidth', 2); % olive color
plot(t, ez, 'r', 'LineWidth', 2);
xlabel('t');
ylabel('Errors');
legend('e_x', 'e_y', 'e_z');
title('Synchronization Errors');
grid on;
In this MATLAB script, we are analyzing how two systems synchronize over time. We start by setting parameters and defining a system of differential equations using an anonymous function. Initial conditions are specified, and `ode45`, a MATLAB solver, is used to compute the system's behavior over time. We then calculate synchronization errors to assess how well the systems stay in sync. Finally, these errors are plotted to visually represent their changes over time, providing insights into the systems' synchronization. Feel free to tweak the parameters and initial conditions to explore different scenarios!

3 Comments

Thank you for assisting the OP (@Nehad) in converting the Maple code to MATLAB code. Could you indicate in the plot how both System #1 and System #2 are synchronized over time? I cannot observe this in your two MATLAB scripts as you typed them out individually.
Were the systems originally unsynchronized in the Maple code? I am unfamiliar with Maple, so perhaps @Walter Roberson can provide a little guidance.
Given the same set of initial conditions, Maple produces the same synchronization error plot (with marginally different plot boundaries and no axis box.)
@Walter Roberson, thank you. I was not aware that "X(t) - (alpha1*x(t) + alpha2)*x(t)", "Y(t) - (beta1*y(t) + beta2)*y(t)", and "Z(t) - (delta1*z(t) + delta2)*z(t)" are referred to as synchronization errors between System XYZ and System xyz. However, the OP never referred to these as 'synchronization errors.' This may be a specialized technical term in a particular field.
Initially, I interpreted the OP's use of 'synchronization' as a task to plot the time responses of both systems in a single figure using the 'hold on' command.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Asked:

on 27 Feb 2025

Commented:

on 3 Mar 2025

Community Treasure Hunt

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

Start Hunting!