Clear Filters
Clear Filters

In three system of equation we applied delay two times in one system of equation. Code is showing error. Please do the needful.

2 views (last 30 days)
dde()
function dde()
tspan = [0,5];
ylim([1,5]);
tau = 0.1;
Y0 = [0.005;0.0007;2];
sol = dde23(@dde_system, tau, Y0, tspan);
% Plot the results
figure;
plot(sol.x, sol.y(1,:), 'b', 'LineWidth', 2, 'DisplayName', 'y1');
hold on;
plot(sol.x, sol.y(2,:), 'r', 'LineWidth', 2, 'DisplayName', 'y2');
hold on;
plot(sol.x, sol.y(3,:), 'g', 'LineWidth', 2, 'DisplayName', 'y3');
xlabel('Time');
ylabel('Values');
title('System of Delay Differential Equations with a Delay');
legend('show');
grid on;
end
function dydt = dde_system(t, y, Z)
a=0.0002; p=0.0001; s=0.006; r=0.0005; k=0.0138; q=0.2;
y_tau = Z(:, 1);
dydt = zeros(3, 1);
dy_dt(1) = (r.*y(1)).*(1-(y(1)+y(2))./k)-(a.*y(1).*y(3));
dy_dt(2) = (a.*y_tau(1).*y_tau(3))-(p.*y(2));
dy_dt(3) = (q.*y(2))-(s.*y(3));
end
  3 Comments
Dhivyadharshini
Dhivyadharshini on 4 Jan 2024
Thank you so much for your reply Sir. But the graph should come like a curve. it is coming like a straight line. I also tried this. Please change the code and do the needful sir.
Sam Chak
Sam Chak on 4 Jan 2024
Hi Ms. @Dhivyadharshini, it would be beneficial to revise the description of your "Question" or "Title" to ensure that forum users clearly comprehend your request for a curvy-looking graph.
Additionally, if you require others to review the equations, please include the expected graph and the governing equations (in image form) sourced from textbooks, technical reports, or academic journals. This will facilitate a thorough comparison of the equations.
Similar to how "marking schemes" are provided for teachers to assess students' answers in an examination, providing these details will enhance the clarity of your request.

Sign in to comment.

Accepted Answer

Ayush
Ayush on 4 Jan 2024
Edited: Ayush on 4 Jan 2024
I understand that your code should give you a curve, but it is coming as a straight line. Here are the few issue which I could see:
  • In the dde_system function, you are defining dydt as the output variable, but then you are trying to assign values to dy_dt, which is undefined.
  • You are setting the initial conditions Y0 to very small values, and depending on the parameters of your system, this could result in changes that are not significant enough to be seen as curves in the plot, especially if the system quickly reaches a steady state.
You may try this code:
dde()
function dde()
tspan = [0, 5];
tau = 0.1;
Y0 = [0.005; 0.0007; 2];
sol = dde23(@dde_system, tau, Y0, tspan);
% Check the range of y1 to ensure it's not all zeros or constant
% disp(sol.y(3,:));
% Plot the results
figure;
plot(sol.x, sol.y(1,:), 'b*', 'DisplayName', 'y1');
hold on;
plot(sol.x, sol.y(2,:), 'r', 'LineWidth', 2, 'DisplayName', 'y2');
plot(sol.x, sol.y(3,:), 'g', 'LineWidth', 2, 'DisplayName', 'y3');
xlabel('Time');
ylabel('Values');
title('System of Delay Differential Equations with a Delay');
legend('show');
grid on;
% Adjust ylim based on the range of y1
ylim([-0.1, 2]);
end
function dydt = dde_system(t, y, Z)
a = 0.0002; p = 0.0001; s = 0.006; r = 0.0005; k = 0.0138; q = 0.2;
y_tau = Z(:, 1);
dydt = zeros(3, 1);
dydt(1) = (r * y(1)) * (1 - (y(1) + y(2)) / k) - (a * y(1) * y(3));
dydt(2) = (a * y_tau(1) * y_tau(3)) - (p * y(2));
dydt(3) = (q * y(2)) - (s * y(3));
end
Thanks,
Ayush
  1 Comment
Dhivyadharshini
Dhivyadharshini on 4 Jan 2024
Thank you for your reply sir. My actual ode equation is this
dydt(1) = (r * y(1)) * (1 - (y(1) + y(2)) / k) - (a * y(1) * y(3));
dydt(2) = (a * y(1) * y(3)) - (p * y(2));
dydt(3) = (q * y(2)) - (s * y(3));
And my DDE equation is this
dydt(1) = (r * y(1)) * (1 - (y(1) + y(2)) / k) - (a * y(1) * y(3));
dydt(2) = (a * y(1) * (t-tau) * y(3) * (1-tau)) - (p * y(2));
dydt(3) = (q * y(2)) - (s * y(3));
parameter values are:
a = 0.0002; p = 0.0001; s = 0.006; r = 0.0005; k = 0.0138; q = 0.2;
Initial conditions are:
Y0 = [0.005; 0.0007; 2];
Please check the equation sir and give the code for this dde. Do the needful for getting the curve sir.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!