H = [0.2];
Y_euler = cell(1,numel(H));
for k=1:numel(H)
h = H(k);
x = 0:h:60;
y = zeros(1, numel(x));
y(1) = 250;
n = numel(y);
for i=1:n-1
f = ((0.00003*y(i))*(25000-y(i)));
y(i+1) = y(i) + h * f;
end
Y_euler{k} = [x; y].';
end
syms Y(X)
eq = diff(Y) == (0.00003*Y)*(25000-Y);
ic = Y(0) == 250;
sol = dsolve(eq, ic);
y_sol = double(subs(sol, X, x));
hold on
plot(x, y_sol, 'r', 'DisplayName', 'true solution');
for k=1:numel(H)
plot(Y_euler{k}(:,1), Y_euler{k}(:,2), 'b--', 'DisplayName', ['Euler method h=' num2str(H(k), '%.3f')]);
end
legend
This is my attempt, but I still can't find a way to find the arithmetic mean.
