clear all; % good to start by clearing all old variables alpha = 0.2; % alpha will be rate of decay, one-over-the-timeconstant dt=0.001; % time-step size: always check if making it smaller affects the results T=0:dt:10; % T is a vector from 0 to 10 in steps of dt --- in this case 10001 elements xstart = 100.0; % this will be the initial value of x --- where x starts from x=zeros(size(T)); % x is a vector the same as T but with every element set to zero x(1) = xstart; % now the first element in x is set to xstart. This corresponds to a time of zero since T(1)=0 for ( i = 2: length(T) ) % beginning of a loop with i =2 first time, then 3, then 4 ... until i = 10001 as length(T)=10001 x(i) = x(i-1) - x(i-1)*dt*alpha; % change in x is -x*dt*alpha solves the eqn: dx/dt = -alpha*x end % end of for loop, so go back to line 8 unless i has reached 10001 already x(end) % this just prints out the last value of x figure(1); % start a figure called figure(1) plot(T,x); % plot x against T