You are on page 1of 9

Differential Equations Solver

Page 1 of 9

Differential Equations Solver


See Also: Linear Equations Solver Nonlinear Equations Solver
Expand All | Collapse All

Overview

The purpose of this program is to provide a solution for a system of simultaneous first-order ordinary differential equations and explicit algebraic equations. The equation input/modification window is shown below for a typical problem:

The options and information available on this screen are the following: Icon Description Add DE: Input a new differential equation Add EE: Input a new explicit algebraic equation inifinl Define initial and final values of the independent variable Opens a window showing a list of defined and undefined variables Problem setup state. Blue color - complete, ready to be solved. Problem setup state. Red color - incomplete (missing definition, initial state etc.). Integrate the system of equations. Note that this option is displayed only when a valid set of equations, including initial and final values of the variables, has been entered. Table: When this option is marked, a table containing the values of all the variables as function of independent variable is created during integration. Graph: When this option is marked, a plot of the integrated values of the differential variables versus the independent variable is created during integration. Report: When this option is marked, a report containing initial, final, maximal and minimal values of all the variables, a complete listing of the equations in the system, and some additional information is shown after the integration is finished. Algorithm Drop-down box: Select the preferred solution algorithm identified in the pull down menu. At the bottom of the window the numbers of differential and the auxiliary equations are shown and problem setup related warning messages (undefined variables, missing initial values etc.) are displayed. Additional detailed information is provided with regard to the following: Entering the Equations into the Program Variables and Expressions Integration Algorithms Solution Report, Tabular and Graphic Presentation of the Results Troubleshooting

mk:@MSITStore:C:\Program%20Files\Polymath%20Software\Polymath%20Fogler\po... 3/21/2013

Differential Equations Solver

Page 2 of 9

Entering the Equations

The system of equations may contain two types of equations: first order ordinary differential equations and explicit algebraic equations where one of the variables can be expressed as explicit function of other variables and constants. The differential equations must be entered in the following form: d(x)/d(t)= an expression Here t is the independent variable and x is a dependent variable. Auxiliary algebraic equations must be entered in the form: x = an expression where the same naming rules apply. An expression may contain any combination of constants and variables. However, the auxiliary equations must be sequential (not simultaneous). POLYMATH will sort and order the equations and will indicate if a simultaneous situation exists (by warning of 'circular dependency'). Initial conditions must be specified for all the variables defined by differential equations, as well as the independent variable. A final value must also be specified for the independent variable. Entering Ordinary Differential Equations To input a new set of equations for solution, select differential equations (DEQ) from the file menu. To input a differential equation, press the Add DE button. The following dialog box opens:

In this dialog box enter the name of a differential dependent variable between the brackets of the d( )/d( ) in the top left field that is left of the = sign. Enter the independent variable in the bottom of the d( )/d( ) field. Note that this defines the independent variable for subsequent differential equation entry. Enter the right hand side expression in the window after the = sign and finally enter an initial value for the dependent variable. You can enter comments (describing the variable and its units for example) if you wish. Press Done to finish entering the equation. Entering Explicit Equations To input an explicit equation, press the Add EE button. The following dialog box opens:

mk:@MSITStore:C:\Program%20Files\Polymath%20Software\Polymath%20Fogler\po... 3/21/2013

Differential Equations Solver

Page 3 of 9

In this dialog box enter the name of a variable in the box to the left of the = sign. Enter the right hand side expression into the window on the right of the = sign. Press Done to finish entering the equation. Equations can be edited or removed by highlighting the row in which the particular equation is found and pressing the Edit or Remove buttons. Before a set of equations can be solved all the variables must be defined, thus every one of them must appear in the left side of either an implicit or an explicit equation. Entering Boundary Conditions

The initial and final boundary conditions must be entered for the independent variable. This is accomplished by pressing the button that opens the following windows for the initial value and the final values respectively:

Variable Tracking A convenient feature of Polymath is that the undefined variables and missing initial/final conditions are indicated directly above the entry window. This is shown below for missing explicit variable k2 (to the right of the red X):

This feature helps you to insure that missing or misnamed variables are identified and easily entered or corrected. Also note that pressing or choosing "Show Variables..." from the "Problem" drop-down menu opens a window with a summary of the problem variables as shown below:

mk:@MSITStore:C:\Program%20Files\Polymath%20Software\Polymath%20Fogler\po... 3/21/2013

Differential Equations Solver

Page 4 of 9

Ordering of Equations You need not be concerned with the order in which you enter the equations or the initial/final conditions. Polymath will automatically order the equations during problem solution. You may have your equations ordered at any time by selecting "Order Equations" from the drop-down "Problem" menu. Editing Equations Standard editing is available for entered equations from the "Edit" drop-down menu. Also note that you can copy an expression or part of it while in the equation entry dialog box or in the entered equation by marking it and pressing Ctrl+C. Pasting involves the key press combination Ctrl+V. Experienced users can use the full-screen Polymath editor directly to enter all equations and boundary conditions. This feature also allows you to copy all or parts of other Polymath programs to your current problem. The "#" character can be used to put a comment in the program text. Note: You may see the valid expressions and variables in Variables and Expressions Integration Algorithm Selection The drop-down menu provides a selection of available integration algorithms that can be used in problem solution as shown below with the default algorithm highlighted. These algorithms will be discussed in another section.

Program Output Selection The selections are made by checking the appropriate boxes in the problem display:

Table - This option provides a table of all the problem variables at each of the values of the independent variable as it is varied from the initial condition to the final value. This summary table can be used to generate graphs within Polymath or these data can be copied and pasted into spreadsheet or graphical programs. Graph - This option formulates a graph of all the differential equation variables plotted with the independent variable. Various options within Polymath from this graphical display allow for editing of the graph and the display of selected problem variables. Report - This option generates a summary of all the problem variables indicating the initial value, minimal value, maximal value, and final value of each variable. Additionally, all the equations are summarized and details regarding the numerical solution are given. The above program outputs are presented in the example problem that follows.

Example
Example 1: Three Simultaneous Ordinary Differential Equations and Two Explicit Algebraic Equations

Consider the following set of equations: d(A)/d(t)= - k1A d(B)/d(t)= k1A k2B d(C)/d(t)= k2B that is to be integrated from t=0 where A(0)=1, B(0)=0 and C(0)=0 (initial values) for up to t=3 with the constant values being: k1=1 and k2=2. The equations can be inputted in any order as Polymath will order the equations prior to integration. To input the first differential equation, press the Add DE button. In the dialog box that opens put A (without the quotation marks) in the box between the parentheses of: d()/d(t)=. Put the expression: -k1*A (without the quotation marks) in the

mk:@MSITStore:C:\Program%20Files\Polymath%20Software\Polymath%20Fogler\po... 3/21/2013

Differential Equations Solver

Page 5 of 9

window after the = sign. (Note that POLYMATH does not allow use of subscripts or superscripts). Finally enter the initial value 1.0 for A(0). The equation entry dialog box with the completed first equation is shown below.

Enter the second and third differential equations according to the above procedure must be repeated when the appropriate variable names, expressions and initial values are inputted in the dialog boxes. To enter the constant values, the option Add EE should be used. To enter the value of k1, press the Add EE button. In the dialog box that opens put k1 in the box preceding the = sign and put 1.0 in the window after the equal sign. The completed dialog box is shown below.

Press Done to finish entering this constant. Assign a value to k2 similarly. Before the integration can be carried out the initial and final values of the independent variable must also be specified. The final form of the system of equations with the appropriate initial and final values, ready to be solved is shown below.

The program output selection is discussed in the section entitled Solution Report.

Integration Algorithms

There are five numerical integration algorithms available within Polymath. The two most useful algorithms will be discussed in

mk:@MSITStore:C:\Program%20Files\Polymath%20Software\Polymath%20Fogler\po... 3/21/2013

Differential Equations Solver

Page 6 of 9

some detail. RKF45 The Runge-Kutta-Fehlberg (RKF45) is the default algorithm that is highly recommended for most problems. Details are available in the paper by Forsythe et al, 1977. This algorithm monitors the estimate of the integration error, and reduces or increases the step size of the integration in order to keep the error below a specified threshold. The accuracy requested is that both the relative and absolute (maximal) errors be less than the truncation error tolerance. The default value of this tolerance is 1.0E-6. (All the tolerances can be changed in Settings). If the integration progresses very slowly the reason for that may be that the system of equations is stiff. Stiff systems of equations contain variables that change (decay) in widely varying time scales. For such systems, the RKF algorithm may require a very small step size for integration and one of the available still algorithms, STIFF or STIFFBS, should be used. STIFFBS The recommended stiff algorithm is the semi-implicit midpoint rule of Bader and Deufhand (STIFFBS). Details are available in the paper by Bader and Deufhand, 1983. This algorithm also includes error estimation and step-size control. In this case, the requested maximal error tolerance is 1.0E-7 Other Algorithms (RKF56, BS, STIFF) Additional algorithms include a higher order (higher precision) such as the Runge-Kutta-Fehlberg (RKF56). The Burlirsch-Stoer (BS) uses the extrapolation method. When this is used for non-stiff problems, and it requires less computational effort than the RKF methods in order to achieve the same high accuracy during the integration of smooth functions. Details are found in Press et al, 1992, pp. 735-739. For stiff problems the Rosenbrock method (STIFF) is also available. This method is simple to implement. For moderate accuracy and moderate sized systems, it is competitive with the more complicated algorithms. More information is also available in Press et al, 1992, pp. 735-739).

Solution Outputs

The output options are discussed below using the problem from Example 1: Report It is recommended that the Report always be one of the output options. This Example 1 report is presented below:

mk:@MSITStore:C:\Program%20Files\Polymath%20Software\Polymath%20Fogler\po... 3/21/2013

Differential Equations Solver

Page 7 of 9

The initial part of the Report indicates the title of the problem as entered by the user and the date when the solution was obtained. This is followed by a table showing initial, minimal, maximal and final values for all the variables in the problem. The next section of the report displays the original equations separated into differential equations and explicit equations along with the comments, as entered by the user. The final part of the report given below summarizes the problem equation, the execution time, the solution method, and the location where the problem file is stored.

The report is of significant value in checking to see that the problem is functioning properly and that the expected variables have the desired values. You may also find that copying this Report into a word processing document provides an easy way to document a particular problem. Graph When the graph option is checked, a graph containing all the integrated differential variables versus the independent variable are displayed with automatically scaling. The initial graph for the example is displayed below:

mk:@MSITStore:C:\Program%20Files\Polymath%20Software\Polymath%20Fogler\po... 3/21/2013

Differential Equations Solver

Page 8 of 9

The options available on left side of this Graph display screen are summarized below. Please click on the description for more detailed information on selected options. Icon Description Refresh: Graph is restored to original state. Save: Creates a Polymath Graph file as *.plg Save As: Creates a new Polymath Graph file as *.plg Open: Opens a Polymath Graph file Print: Prints the current Graph Copy: Copies the current Graph to the clipboard Curves and Functions: Allows selection of variable for revised Graph Design: Allows changes in Graph properties Table: Creates data table for selected curves Changing Displayed Variables In the simple graph displayed above, the independent variable of the integration is being displayed on the horizontal (x) axis by default. The variable appearing on the x axis and the variables plotted on the vertical (y) axis can be controlled by clicking on the "Curves and Functions" icon. Scaling Displayed Variables If the magnitudes of the displayed variables differ widely, the details of some of the curves may be lost. The option to hide or show variables (in Curves and Functions) can be used to obtain graphs that are better scaled for a particular range. Manual rescaling of the graph can also lead to the same results. Additional options for editing and manipulating the graph are discussed in the Graph" section. Smoothing Displayed Curves When some of the curves are non-smooth and appear broken, this may be improved by increasing the number of data points saved during the integration and/or by reducing the integration interval. The default value for intermediate data points is 100. Increasing this up to 500 for the Ordinary Differential Equations (in settings) will usually lead to smooth, unbroken curves. Curves and Functions Design Table Details

Troubleshooting

Most of the error messages issued by the program are self-explanatory and suggest the type of action that should be taken to

mk:@MSITStore:C:\Program%20Files\Polymath%20Software\Polymath%20Fogler\po... 3/21/2013

Differential Equations Solver

Page 9 of 9

correct the problem. In some cases, however, no error message is given or the message is less obvious. Common errors and the suggested corrective actions are presented in below.

The arrow

is not shown after finishing equation input.

The appearance of the pink arrow on the equation input window indicates that the problem has been completely defined and the program is ready to solve it. There are two common reasons for the arrow not to be pink: 1. There are still undefined variables. Open the window by clicking on the icon to show the list of defined and undefined variables. Use of letters and numbers with similar symbols (such as the letter I and the number 1 (one)) often causes the same variable to show up with different names. No initial and/or final value for the independent variable has been entered. Input initial and final values (You can press the Tab key after finished entering the first number).

2.

Circular definition of explicit variables not allowed.

This message appears while the program is trying to solve a set of equations, when one (or more) variable is defined as a function of another variable, which itself is a function of the first variable. For example, attempting to define y=z/x, when z was already defined as a function of y, will cause this error message. Note that implicit algebraic equations are not allowed in the differential equation solver. To solve such (differential algebraic) systems with POLYMATH, the method by Shacham et al (1996) can be used.
Division by zero at the starting point.

Occasionally the initial value of a variable must be zero, but this value causes one or more equations to be undefined. Starting the integration using a value of eps (where eps is a very small number) for this variable instead of 0 can often solve this difficulty.
Some of the curves appear non-smooth when graphical results are displayed.

When some of the curves are non-smooth and appear broken, this may be improved by increasing the number of data points saved during the integration and/or by reducing the integration interval. The default value for intermediate data points is 100. Increasing this up to 500 for the Ordinary Differential Equations (in settings) will usually lead to smooth, unbroken curves.
Integration progresses very slowly (error message Too many steps )

Some of causes and cures for very slow integration are: 1. The integration algorithm is not appropriate. It may happen that the problem is very stiff and a non-stiff algorithm (such as RKF45) is used for integration. Try to change the integration algorithm to a stiff method (such as STIFFBS or STIFF). If the error message persists, check for other potential causes. The ratio between the integration interval and the error tolerance is too large. The integration algorithm will attempt to achieve precise solution as dictated by the error tolerance; therefore, very small step sizes are used. The resulting calculations take too many steps and thus too much time to cover the entire interval using such small steps. Try to increase the error tolerance if a less accurate solution is acceptable (in settings) or reduce the interval (final value) for integration. There are errors in the problem setup. If the error message still persists after reducing the integration interval and changing integration method, there are probably errors in the problem setup or input. Check and verify that the basic equations of the problem are correct. Double check the entered problem, the numerical values used, and the units of the equations and various constants.

2.

3.

mk:@MSITStore:C:\Program%20Files\Polymath%20Software\Polymath%20Fogler\po... 3/21/2013

You might also like