# Ecological Models v. 1.2 (September 2005) # Dr. Maeve McCarthy, # Brandon Hale # Murray State University # It is recommended that this program be run while reading the accompanying text, Ecological Models.doc. # Please do not alter this code. For more information about this program, run it and click the "About this Program" button in the Main window. with(Maplets): with(Maplets[Elements]): # The following sets up the procedure used for the Logistic Graph Maplet. It reports the equation (TF4) and graph (PL1), based on the parameters given by the user. plotdatalog := proc(p,m,r,st) #Maplets[Elements][Evaluate]('function' = "decision2", Argument(Maplets[Tools][Get](thismaplet, 'stoptime'::algebraic))); Maplets[Tools][Set](thismaplet, 'TF4' = evalf[4]('r*P(t)*(m-P(t))/m')); Maplets[Tools][Set](thismaplet, 'PL1' = DEtools[DEplot](diff(P(t),t)=Maplets[Tools][Get](TF4::algebraic), [P(t)], t=0..st, [[P(0)=p]], P(t)=0..(max(p,m)+0.1*max(p,m)), labels=[Time, "Pop."], stepsize=min(0.05, st/300)) ); end proc: # The following sets up the Logistic Graph Maplet. The user input text fields (TF1, TF2, TF3, and stoptime) are used as arguments for the procedure above, with default values specified. TF4 is used to display the equation. logistic := Maplet(Window('title'="Ecology Models v1.2", [ "Logistic Equation", Plotter['PL1']( 'height'=300, 'width'=450 ), GridLayout( GridRow('halign'=left, "Enter Initial Population (P0):", GridCell(TextField['TF1'](10, 'value'="900")) ), GridRow('halign'=left, "Enter Carrying Capacity (K):", GridCell(TextField['TF2'](10, 'value'="1073")) ), GridRow('halign'=left, "Enter Rate of Increase (r): ", GridCell(TextField['TF3'](10, 'value'="0.2311")) ), GridRow('halign'=left, "Enter Stop Time: ", GridCell(TextField['stoptime'](10, 'value'="25" )) ), GridRow('halign'=left, "Differential Equation: dP/dt=", GridCell(TextField['TF4'](20, 'editable'='false')) )), [Button("Graph", Evaluate('function' = "plotdatalog", Argument('TF1'), Argument('TF2'), Argument('TF3'), Argument('stoptime')) )],[Button("Close", Shutdown())] ])): # Procedure for the Logistic with Harvesting Maplet. It reports the equation (TF5) and graph (PL1), based on the parameters given by the user. plotdatalh := proc(p,m,r,h,st) Maplets[Tools][Set](thismaplet, 'TF5' = evalf[4]('r*P(t)*(m-P(t))/m-h*P(t)')); Maplets[Tools][Set](thismaplet, 'PL1' = DEtools[DEplot](diff(P(t),t)=Maplets[Tools][Get](TF5::algebraic), [P(t)], t=0..st, [[P(0)=p]], P(t)=0..(max(p,m)+0.1*max(p,m)), labels=[Time, "Pop."],stepsize=0.05) ); end proc: # The following sets up the Logistic Graph with Harvesting Maplet. The user input text fields (TF1, TF2, TF3, TF4, and stoptime) are used as arguments for the procedure above, with default values specified. TF4 is used to display the equation, and the Plotter (PL1) is used to display the graph. logharv := Maplet(Window('title'="Ecology Models v1.2", [ "Logistic Equation with Harvesting", Plotter['PL1']( 'height'=300, 'width'=450 ), GridLayout( GridRow('halign'=left, "Enter Initial Population (P0):", GridCell(TextField['TF1'](10, 'value'="900")) ), GridRow('halign'=left, "Enter Carrying Capacity (K):", GridCell(TextField['TF2'](10, 'value'="1073")) ), GridRow('halign'=left, "Enter Rate of Increase (r):", GridCell(TextField['TF3'](10, 'value'="0.2311")) ), GridRow('halign'=left, "Enter Rate of Harvesting (h):", GridCell(TextField['TF4'](10, 'value'="0.1389")) ), GridRow('halign'=left, "Enter Stop Time: ", GridCell(TextField['stoptime'](10, 'value'="25")) ), GridRow('halign'=left, "Differential Equation: dP/dt=", GridCell(TextField['TF5'](20, 'editable'='false')) )), [Button("Graph", Evaluate('function' = "plotdatalh", Argument('TF1'), Argument('TF2'), Argument('TF3'), Argument('TF4'), Argument('stoptime')) ) ], [Button("Close", Shutdown())] ] )): # Procedure for the Explosion-Extinction Maplet. plotdataee := proc(p,m,r,st) Maplets[Tools][Set](thismaplet, 'TF4' = evalf[4]('r*P(t)*(P(t)-m)/m')); Maplets[Tools][Set](thismaplet, 'PL1' = DEtools[DEplot](diff(P(t),t)=Maplets[Tools][Get](TF4::algebraic), [P(t)], t=0..st, [[P(0)=p]], P(t)=0..(max(p,m)+0.1*max(p,m)), stepsize=0.05) ); end proc: # The following sets up the Logistic Graph with Harvesting Maplet. The user input text fields (TF1, TF2, and TF3) are used as arguments for the procedure above, with default values specified. TF4 is used to display the equation, and the Plotter (PL1) is used to display the graph. expext := Maplet(Window('title'="Ecology Models v1.2", [ "Explosion-Extinction Equation", Plotter['PL1']( 'height'=300, 'width'=450 ), GridLayout( GridRow('halign'=left, "Enter Initial Population (P0):", GridCell(TextField['TF1'](10, 'value'="12")) ), GridRow('halign'=left, "Enter Minimum Sustainable (M):", GridCell(TextField['TF2'](10, 'value'="10")) ), GridRow('halign'=left, "Enter Rate of Increase (r):", GridCell(TextField['TF3'](10, 'value'="0.03")) ), GridRow('halign'=left, "Enter Stop Time: ", GridCell(TextField['stoptime'](10, 'value'="100")) ), GridRow('halign'=left, "Differential Equation: dP/dt=", GridCell(TextField['TF4'](20, 'editable'='false')) )), [Button("Graph", Evaluate('function' = "plotdataee", Argument('TF1'), Argument('TF2'), Argument('TF3'), Argument('stoptime')) ) ], [Button("Close", Shutdown())] ])): # Procedure for the Explosion-Extinction with Harvesting Maplet. It reports the equation (TF5) and graph (PL1), based on the parameters given by the user. plotdataeh := proc(p,m,r,h,st) Maplets[Tools][Set](thismaplet, 'TF5' = evalf[4]('r*P(t)*(P(t)-m)/m-h*P(t)')); Maplets[Tools][Set](thismaplet, 'PL1' = DEtools[DEplot](diff(P(t),t)=Maplets[Tools][Get](TF5::algebraic), [P(t)], t=0..st, [[P(0)=p]], P(t)=0..(max(p,m)+0.1*max(p,m)), stepsize=0.05) ); end proc: # The following sets up the Explosion-Extinction Graph with Harvesting Maplet. The user input text fields (TF1, TF2, TF3, and # TF4) are used as arguments for the procedure above, with default values specified. TF5 is used to display the equation, and the Plotter (PL1) is used to display the graph. expexth := Maplet(Window('title'="Ecology Models v1.2", [ "Explosion-Extinction Equation with Harvesting", Plotter['PL1']( 'height'=300, 'width'=450 ), GridLayout( GridRow('halign'=left, "Enter Initial Population (P0):", GridCell(TextField['TF1'](10, 'value'="20")) ), GridRow('halign'=left, "Enter Minimum Sustainable (M):", GridCell(TextField['TF2'](10, 'value'="8")) ), GridRow('halign'=left, "Enter Rate of Increase (r):", GridCell(TextField['TF3'](10, 'value'="0.04")) ), GridRow('halign'=left, "Enter Rate of Harvesting (h):", GridCell(TextField['TF4'](10, 'value'="0")) ), GridRow('halign'=left, "Enter Stop Time: ", GridCell(TextField['stoptime'](10, 'value'="100")) ), GridRow('halign'=left, "Differential Equation: dP/dt=", GridCell(TextField['TF5'](20, 'editable'='false')) )), [Button("Graph", Evaluate('function' = "plotdataeh", Argument('TF1'), Argument('TF2'), Argument('TF3'), Argument('TF4'), Argument('stoptime')) ) ], [Button("Close", Shutdown())] ])): # The following sets up the About window. aboutprog := Maplet(Window['abt']('title'="About this Program", [ GridLayout( GridRow(GridCell("Ecology Models v1.2 (Released September 2005)")) ), [""], GridLayout( GridRow(GridCell("By: Dr. Maeve McCarthy and Brandon Hale")), GridRow(GridCell("Murray State University (Murray, KY)")) ), [""], GridLayout( GridRow(GridCell("Financial Support Provided By:")), GridRow(GridCell("Office of Undergraduate Research And Scholarly Activities")) ), [""], GridLayout( GridRow(GridCell("Special Thanks To:")), GridRow(GridCell("John Mateja, Phil Schooley, and Dr. Howard Whiteman")) ), [Button("OK", Shutdown())] ])): # This procedure calls the About window. dispabout := proc() Maplets[Display]( aboutprog ) end proc: # This procedure is used to decide which window to call. It uses arguments a, b, and c (see below for an explanation of this), and calls the appropriate window based on which are defined as true. decision := proc(a,b,c) if a then if c then Maplets[Display]( logharv ); # If a and c are both true, call the Logistic with Harvesting Maplet else Maplets[Display]( logistic ); # If a is true but c is not, call the simple Logistic Maplet end if; elif b then if c then Maplets[Display]( expexth ); # If b and c are both true, call the Explosion-Extinction with Harvesting Maplet else Maplets[Display]( expext ); # If b is true but c is not, call the simple Explosion-Extinction Maplet end if; end if; end proc: # This procedure is used to decide what step size to use for the numerical integration. It chooses either 0.05 #or time/300, whichever is the smaller. #decision2 := proc(st) # global stpsz; # if (st/300 < 0.05) then (stpsz = st/300); # else (stpsz = 0.05); # end if; #end proc: # This is the code for the Main window. It has two radio buttons and a check box, which are fed to the decision procedure by the OK button as arguments a, b, and c (each are true/false). Another button (Close) shuts the program down, and a third button (About this Program) calls the About window. popgrowth := Maplet(Window['Main']('title'="Ecology Models v1.2", [ [RadioButton['RB1']( "Logistic", 'value'=true, 'group'='BG1'), RadioButton['RB2']( "Explosion-Extinction", 'value'=false, 'group'='BG1')], [CheckBox['CB1']( caption="Include Harvesting", 'value'=false)], [Button("OK", Evaluate('function'="decision", Argument('RB1'), Argument('RB2'), Argument('CB1'))), Button("Close", Shutdown())], [Button("About This Program", Evaluate('function' = "dispabout"))]]), ButtonGroup['BG1']()): Display(popgrowth);