As I see you have ended the second function wrongly at the function call "Program_2_1(0.0006,0.0083,50,1,720);" and also "legend" is used incorrectly, here is the corrected version of the above snippet :
clc;
clear;
function dPop = Diff_2_1(t, pop, parameter)
beta = parameter(1);
gamma = parameter(2);
S = pop(1);
I = pop(2);
R = pop(3);
dPop = zeros(3,1);
dPop(1) = -beta * S * I;
dPop(2) = beta * S * I - gamma * I;
dPop(3) = gamma * I;
end
function [t, S, I, R] = Program_2_1(beta, gamma, S0, I0, MaxTime)
R0 = 0; % Initial condition for R
[t, pop] = ode45(@(t, y) Diff_2_1(t, y, [beta gamma]), [0 MaxTime], [S0 I0 R0]);
S = pop(:,1);
I = pop(:,2);
R = pop(:,3);
plot(t, S, '-r', t, I, '-g', t, R, '-b')
xlim([0 200])
xlabel('Time', 'fontweight', 'bold')
ylabel('Number', 'fontweight', 'bold')
legend('S', 'I', 'R') % Directly pass the strings for the legend
end
% Call the function
[t, S, I, R] = Program_2_1(0.0006, 0.0083, 50, 1, 720);