% logist4.m
% Matlab file for Part 4 of the Logistic Growth module
global r K
disp('**********************************************')
disp('Part 4: Symbolic Solutions')
disp('**********************************************')
disp(' ')
format short
disp('Step 1: ')
disp('Separate variables and integrate both sides.')
disp(' ')
disp('Recall that the MATLAB command for integrating')
disp('with respect to variable P looks like ')
disp(' ')
disp(' int( ?, P) ')
disp(' ')
disp(' (You have to fill in the question mark with ')
disp(' the function of P you are integrating. All ')
disp(' symbolic variables must have been declared ')
disp(' using ''syms''.) ')
disp(' ')
disp('When you are finished, to continue, type the')
disp('word return and hit enter!')
disp(' ')
keyboard;
disp(' ')
disp('----------------------------------------------')
disp('Step 2:')
disp('Add a constant C1 to the right hand side after')
disp('integrating. (Declare C1 symbolic). Then')
disp('solve for P as a function of t. ')
disp(' ')
disp('Recall that the MATLAB command for solving an ')
disp('equation for P looks like')
disp(' ')
disp(' solve( ?, P) ')
disp(' ')
disp(' (You have to fill in the question mark with ')
disp(' the equation you are solving, enclosed in')
disp(' single quote marks.) ')
disp('-----------------------------------------')
disp(' ')
disp('When you are finished, to continue, type the')
disp('word return and hit enter! ')
disp(' ')
keyboard;
disp(' ')
disp('----------------------------------------------')
disp('Step 3:')
disp('Now, we will solve the logistic differential')
disp('equation directly, using MATLAB''s DE solver.')
disp(' ')
disp('Enter: ')
disp(' ')
disp(' syms r K P t ')
disp(' LDE ='' DP = r*P*(1 - P/K) '' ')
disp(' P = dsolve(LDE) ')
disp(' pretty(P) % Gives nice format ')
disp(' ')
disp('When you are finished, to continue, type the')
disp('word return and hit enter! ')
disp(' ')
keyboard;
disp(' ')
disp('----------------------------------------------')
disp('Step 4:')
disp('Reconcile any differences you see between the')
disp('the formulas you got in steps 2 and 3.')
disp('Explain using MATLAB comments in your diary file.')
disp(' ')
disp('When you are finished, to continue, type the')
disp('word return and hit enter! ')
disp(' ')
keyboard;
disp(' ')
disp('----------------------------------------------')
disp('Step 5:')
disp('Handle the case for P > K. Explain your results')
disp('using MATLAB comments in your diary file. ')
disp(' ')
disp('When you are finished, to continue, type the')
disp('word return and hit enter! ')
disp(' ')
keyboard;
disp(' ')
disp('----------------------------------------------')
disp('Step 6:')
disp('Determine the arbitary constant C1 in terms of')
disp('P0 and K. Simplify you solution as much as')
disp('possible. Explain your results in you diary')
disp('file by using MATLAB comments.')
disp(' ')
disp('When you are finished, to continue, type the')
disp('word return and hit enter! ')
disp(' ')
keyboard;
disp(' ')
disp('----------------------------------------------')
disp('Step 7:')
disp('Explain why P(t) appoaches K as t becomes large.')
disp('Use MATLAB comments in your diary file.')
disp(' ')
disp('When you are finished, to continue, type the')
disp('word return and hit enter! ')
disp(' ')
keyboard;
disp(' ')
disp('----------------------------------------------')
disp('Step 8:')
disp('You can plot the direction field for the logistic')
disp('equation by using m-files provided with this ')
disp('module. The function ''dfun'' defines the right')
disp('hand side of the logistic DE which is needed by ')
disp('the function ''slpfield'' that plots the direction')
disp('field. ')
disp(' ')
disp('You can change the parameters r and K below to')
disp('any values you like. The parameters are passed')
disp('as global variables to the dfun function.')
disp(' ')
disp('Enter: ')
disp(' ')
disp(' r = 0.5 ')
disp(' K = 1 ')
disp(' clf % Clears figure window ')
disp(' slpfield(0,10, 0,K+0.5) ')
disp(' hold on % Holds plot ')
disp(' ')
disp('When you are finished, to continue, type the')
disp('word return and hit enter! ')
disp(' ')
keyboard;
disp(' ')
disp('----------------------------------------------')
disp('Step 8 (cont.):')
disp('To plot your solution P(t) on top of the ')
disp('slope field, use the usual procedure.')
disp(' ')
disp('First make sure P0, r, and K are defined: ')
disp(' ')
disp(' P0= ? ')
disp(' r = 0.5 ')
disp(' K = 1 ')
disp(' ')
disp('Then define your range of t values and')
disp('fill in your solution function below.')
disp(' (Don''t forget a period before the divide')
disp(' sign when defining Psol.) ')
disp(' ')
disp('Then enter the plotting commands: ')
disp(' ')
disp(' t = 0: 0.1: 10; ')
disp(' Psol = ? ;')
disp(' plot(t,Psol,''r'') ')
disp(' axis([0,10, 0,K+0.5]) ')
disp(' ')
disp('----------------------------------------------')
disp('Change the value of P0 and replot the solution')
disp('on top of the previous plot. ')
disp(' ')
disp(' ')
disp('----------------------------------------------')
disp('To go on to Part 5 of this module,')
disp('type: logist5.')
disp(' ')