function [sol1] = two_system
clc
close all
clear all
global z; %%problems
%%1- The indices for the two systems cannot be equal.
%%2- The global function is only valid for one value of (MD) ...
%%(the last value), while I need all values from the first system.
z= 0.05;
tau = 0.1;
tspan = linspace(0, 5, 300);
opt = odeset('RelTol',1e-3);
sol1 = dde23(@system1,tau ,[0],tspan, opt);
[x1, y1] = ode23(@system2, tspan, [0], opt);
figure(1)
plot(sol1.x, sol1.y(1,:),'--r','LineWidth',1.5)
hold on
plot(x1, y1(:,1),'b','LineWidth',1.5)
L2=length(x1)
L1=length(sol1.x)
end
function dydt = system1(t,y,D)
global z MD;
M1 = y(1);
MD = D(1);
s1 = MD %for checking
F_M1= 2;
theta1=0*pi/180;
A1 = 0.01;
%%%%%%% equation_system1 %%%%%%%
dMdt=(A1*(2*pi*(F_M1))*cos(2*pi*(F_M1)*(t)+theta1));
dydt = [dMdt];
end
function dydt = system2(t,y)
global z MD;
s2=MD %% for checking
M2 = y(1);
F_M2= 2;
theta2=0*pi/180;
A2 = 0.01;
%%%%%%% equation_system2 %%%%%%%
dMdt=(A2*(2*pi*(F_M2))*cos(2*pi*(F_M2)*(t)+theta2))+MD*z;
dydt = [dMdt];
end