% 1. if a line starts with % - this line is a comment and will not be executed % by matlab % 2. if a line ends with ; - the result of the execution of this line will not % appear on the screen. try to omit ; after one of the lines below and see what happens %%%%%%%%%% % MAIN PART %%%%%%%%%% %set up parameter values dt=0.5; %days alpha=0.3; % 1/day p_dt=alpha*dt; % define initial condition: I0=100; % define time points (vector t) in which we want to compute our solutions % t is from 0 to 15 with 0.5 day increments % if you omit ; here you will see all components of the vector t t=0:0.5:15; %Now compute the solutions: %continuous: I_Cont=I0*exp(-alpha*t); %notice that I_Cont will be the same length as t. the operation will be %performed to each component of the vector t %discrete: % convert t to discrete points n=0:length(t)-1; % when the increment is 1 it can be omiited %solution: I_Disc=I0*(1-p_dt).^n; %%%%%%%%%%% % plotting %%%%%%%%%% %open figure figure(1) %type 'help plot' in command window to find out how this command works % you can do the same with any other command. also helpwin will open a % whole help window and help help will give you some basic menus plot(t,I_Cont) % prevent future drawings on the same graph from erasing the existing one hold on plot(t,I_Disc,'o') %label axis xlabel('Time, days') ylabel('Number of infected individuals') %%%%%%%%%%%%%%% %PART II %%%%%%%%%%%%%% %do the same for different alpha and plot in red alpha=0.2; p_dt=alpha*dt; %continuous: I_Cont=I0*exp(-alpha*t); %discrete: I_Disc=I0*(1-p_dt).^n; plot(t,I_Cont,'r') plot(t,I_Disc,'or')