In three system of equation we applied delay two times in one system of equation. Code is showing error. Please do the needful.
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Sam Chak
2024-1-4
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.
采纳的回答
Ayush
2024-1-4
编辑:Ayush
2024-1-4
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!