Experiencing discrepancies in octave plotting, T values appearing incorrect due to initial conditions rather than Euler's method results.
I am currently facing an issue while plotting graphs using Euler's method in MATLAB. I have successfully implemented the iterative formula for the differential equation, but when I plot the graph, the displayed T values seem to come from the initial condition (T(1) = 0.025 * K) rather than the expected iterative formula (T(i+1) = T(i) + dt * (mT * T(i) * (1 - (T(i) / K)) - (wT * (G(i) + Gbar(i)) * T(i)) - (jT * T(i) * C(i))).
%Initial condition
C = zeros(length(t), 1);
T = zeros(length(t), 1);
Gbar = zeros(length(t), 1);
G = zeros(length(t), 1);
N = zeros(length(t), 1);
for j = 1:length(C0_values)
C(1) = C0_values(j);
T(1) = 0.025 * K;
Gbar(1) = 0.1 * T(1);
G(1) = K - Gbar(1);
N(1) = K - T(1);
% Plotting T(t) against t for each C0
for i = 2:length(t)-1
% fungsi heaviside
if Gbar(i) + G(i) >= 1
H = 1;
else
H = 0;
end
% Euler method to find the next mutation value
C(i+1) = C(i) + dt * ((Pc * C(i) * (T(i) + Gbar(i))) / (gT + (T(i) + Gbar(i))) - (a * C(i) * T(i)) - ((1/tc) * C(i)));
T(i+1) = T(i) + dt * (mT * T(i) * (1 - (T(i) / K)) - (wT * (G(i) + Gbar(i)) * T(i)) - (jT * T(i) * C(i)));
Gbar(i+1) = Gbar(i) + dt * (mg * Gbar(i) * (1 - (Gbar(i) / Klim)) - (wg * Gbar(i) * T(i)) - (jg * Gbar(i) * C(i)));
G(i+1) = G(i) + dt * (mg * G(i) * (1 - (G(i) / (K - Klim))) - (wg * G(i) * T(i)));
N(i+1) = N(i) + dt * (w * (G(i+1) + Gbar(i+1)) * H * (-1 * (G(i+1) + Gbar(i+1))) * N(i));
end
plot(t, T, 'LineWidth', 0.1, 'DisplayName', sprintf('C0 = %.e', C0_values(j)));
hold on;
end
title('Plot of T(t) against t with Various C0');
I have tried to debug my code, ensuring that variable values are updated at each iteration, but the result remains the same. Can anyone assist me in resolving this issue?
Thank you very much for your help!