|
PolymathPlus Manual |
PolymathPlus is a comprehensive mathematical problem-solving tool. Problems are entered in plain text format, and clicking the ► Solve button generates a detailed numerical solution report.
Linear Equations | Hints |
Nonlinear Equations | Hints |
Ordinary Differential Equations | Hints |
Curve Fit Regression | Hints |
Students, engineers, scientists, or anyone with a need for a numerical math problems-solving package will appreciate the simplicity, efficiency, and speed of PolymathPlus.
System of Linear Equations
The number of equations must be equal to the number of unknown variables. All the algebraic expressions must be linear hence only the plus, minus, and multiplication operators are allowed.
The following example demonstrates the input of a linear system of equations:
Given the following set of 3 linear equations to be solved:
this would be the data entry in the program:
Note that the # sign indicates a user comment line which is ignored by the solution algorithm.
The Solution Report includes the values of the unknowns at the solution (a = 54, b = -4, and c = -2, for this problem) and the problem definition in both matrix and system of equations formats.
System of Nonlinear Equations
When solving simultaneous nonlinear equations, the equations have to be arranged as root expressions (expressions that are equal to zero at the solution).
In addition, an initial guess should be provided for each nonlinear variable.
Rearranging the equations, and estimating x
and y
to be 1 at the solution, this would be the data entry to solve this problem:
you may define any number of auxiliary expressions, to simplify long expressions:
and the resulting solution report will show:
PolymathPlus can numerically solve either a single nonlinear equation or a set of simultaneous nonlinear equations.
When solving a single nonlinear equation, the user has to provide a range of values within which the solution exists.
The program will find all the solutions within that range.
When solving multiple nonlinear equations, the user has to provide a guess for each variable to be found. In this case the guess is a single value and not a range as indicated on the single nonlinear equation.
The nonlinear equations have to be arranged such that all terms are on one side and the other side should be set to zero, essentially building the root expression. The algorithm will search the independent variables which cause the root expression to become zero, or very close to zero.
Additional auxiliary variables can be defined to simplify expressions for repetitive terms.
The problems belonging to this category contain implicit nonlinear algebraic equations that require an iterative solution and explicit algebraic equations where individual variables can be expressed as explicit functions of other variables and constants. An implicit nonlinear equation must be entered in the form:
f(x) = an expression
where x
is the chosen variable name, and f(x)
is an expression that will have the value of zero at the solution.
An explicit equation should be rewritten in the form:
x = an expression
where the expression may contain constants, implicit variables, and explicit
variables.
Only real roots (non-complex) can be found. Multiple roots are determined
for a single equation where the range of the variable must be provided.
Explicit Algebraic Equations
This type of problem contains a set of explicit algebraic equations. Each equation must start with a variable name followed by the equal sign and a linear or nonlinear algebraic expression. The equations may be entered in any order. During the solution, the equations are automatically ordered to achieve a solution. The following system of explicit equations calculates the two roots of a quadratic equation. Note that both problem setups have the same solution.
The Solution Report includes the values of the unknowns (x1 = 7, x2 = 5) and all the variables at the solution.
Note that the equations do not need to be ordered for solution. Keep this option in mind for your general explicit calculational needs.
Single Nonlinear Equation
This option involves the solution of a single implicit nonlinear
equation with any number of explicitly defined variables. The implicit
nonlinear equation must be arranged to an expression which is equal to zero
at the solution.
For the variable associated with the implicit equation,
both minimal and maximal initial estimates must be provided. Multiple roots
are reported if the problem has several solutions (roots) between the
minimal and maximal initial estimates.
The equations and initial estimates
can be entered in any order. PolymathPlus always reorders the equations
during the problem solution.
Solve a nonlinear equation to find the value of x:
The solution is expected to be found between the values 0 - 100.
The problem to enter into PolymathPlus would be:
The Solution Report includes the value/s of the unknown (x=20, in this case), the function value/s (f(x)= 1.0e-8), and the values of all the variables at the solution.
Nonlinear Equations
This option involves the solution of a system comprising of several, implicit, nonlinear algebraic equations with any number of explicitly defined variables. All the implicit equations must be rewritten in the form:
f(x) = an expression
where x is a variable that does not appear on the left hand side of any of the explicit equations and the "expression" must be equal to 0 at the solution. Initial estimates must be provided for all the implicit variables using the syntax: x(0) = a value. The equations may be written in any order.
Example, Solving a set of 2 nonlinear equations:
The Solution Report includes the values of the unknowns (x = 5, y = 20), the function values (f(x)= -2.7E-12, f(y)= 1.3E-12 ) and the values of all the additional variable/s at the solution.
Simultaneous Linear and Nonlinear Equations
A set of simultaneous linear and nonlinear equations can be solved by considering the entire set as nonlinear equations. However, if it is possible to isolate some of the variables and enter them as an explicit expression of other nonlinear variables, we would reduce the number of nonlinear variables to which we need to provide an initial guess, and as a result we would also need to arrange less expressions in a root form (expression which equals to zero). As we get fewer nonlinear equations, we increase the odds of getting a successful solution.Consider a problem containing three linear and two nonlinear equations in the original form:
We could also rewrite the set of equations as two nonlinear equations (root expressions that are set to zero at the solutions), and three explicit expressions. This approach yields:
Note that both programs give the same solution, but the second program requires initial estimates for variables a and c only. The solution is calculated as: a = 1.00011; b = 2.00055; c= 3.00066; d = 3.99967; and e = 4.99964.
Constrained Nonlinear Equations
A special solution algorithm is available for problems where some of the variables can have only positive values.
Consider the following set of equations:
In this problem, the variables x1, x2 and x3 are constrained. At the solution x1>0 because of physical considerations; x2 and x3 must be greater than zero throughout the solution process otherwise a negative value inside the ln function will yield an execution error.
Constraints allowed on the variables of the type x>0 or x<0.
For the solution, the equations for x2 and x3 must be rewritten in the implicit form as shown below:
#@ NLE_SOLUTION_METHOD_INDEX = 3
PolymathPlus designates the constrained variables in the initial guess line as follows: Positive value will have ">= 0" added to the initial guess value, Always positive values will have "> 0" added to the initial guess value.
The entire problem should look like this:
and the solution becomes:
Note that the constrained method may only be used for sets of equations with more than 1 simultaneous nonlinear equation.
Ordinary Differential Equations
An example for an ODE problem is displayed below.
The boundary conditions are: x(0)=1, y(0)=4, t(0)=0, t(f)=1
.
This is the data entry to solve the problem:
or you may define any number of auxiliary expressions, to simplify long and/or repeating sections:
d(x)/d(t) = an expression
Here t is the independent variable and x is a dependent variable. Note that other independent and dependent variable names are possible. 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 explicit (not simultaneous). PolymathPlus 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.
The Solution Report includes a Table listing the initial, minimal, maximal, and final values of all the variables over the integration range. In the example shown, the final values are: A = 0.049787, B = 0.047308 and C = 0.902905. A table containing 50 values of the dependent variables between the initial and final values of the independent variable is also displayed.
Note that the same ODE problem can also be entered in a simplified format such as this:
Regressions of Data
With data regression, we aim to fit a mathematical model to a known set of data points.
This process helps identify a model that best represents the relationship between variables in the data.
PolymathPlus enables users to fit data sets to the following models:
The known data points must be entered in a strict tabulated format, enclosed within square brackets
The first line of the table should contain the variable names, separated by spaces. Subsequent lines must contain the corresponding values for the variables, with columns separated by spaces. All rows must have the same number of columns, and blank values are not permitted. For example:
Tip: Use the Edit > Align Table menu item to align the columns nicely.
Polynomial Regression
PolymathPlus can fit a polynomial of degree n with the general form:
or a linear equation when the equivalent first degree polynomial is specified
where a0, a1, ..., an are regression parameters to a set of N tabulated values of x (a single independent variable) versus y (a single dependent variable). The highest degree allowed for a polynomial is N - 1 (thus n >= N - 1). The program calculates the coefficients a0, a1, ..., an by minimizing the sum of squares of the deviations between the calculated y or P(x) and the data for y.
A polynomial regression is specified by the "polyfit" command that must be followed by the name of the independent variable vector, name of the dependent variable vector, a number representing the degree of the polynomial, and an optional string 'origin' which indicates that the polynomial regression curve must go through the origin. These names must be separated by commas.
Correlation of BOD data example
Consider the following BOD (biological oxygen demand) data versus Time:
Fitting a straight line (linear regression) to the BOD vs. Time data. BOD = a0 + a1*Time
This program yields the results a0 = 0.657797 (±0.374896), (95% confidence intervals shown between parentheses), a1 = 0.178056 (±0.031674), R2 = 0.9472735 and the variance: σ2 = 0.0825304.
In the Solution Report a table containing the observed (measured) y values, the predicted y values (ycalc) and the residuals (r = y- ycalc) are also displayed.
Fitting the data to a 2nd degree polynomial.
To fit a 2nd degree polynomial, the polyfit statement is revised:
The results obtained in this case are a0 = 0.224387 (±0.353054 ), a1 = 0.310403 (±0.081692 ), a2 = -0.006439 (±0.003851), R2 = 0.9815572 and σ2 = 0.0324762.
To fit a 2nd degree polynomial which passes through the origin, the following polyfit statement is used:
For this polynomial a0 = 0, by definition, and the rest of the results are: a1 = 0.354779 (±0.044171), a2 = -0.008236 (±0.002724), R2 = 0.9766053 and σ2 = 0.0366186.
Below are the plots containing: BOD (the data) vs. P(x) (calculated values), and Delta BOD (residuals) vs. time.
Regression Analysis: Judging by the R2 and σ2 values, the 2nd degree polynomial represents the data the best. However, the confidence interval value of a0 shows that this parameter is not significantly different from zero, thus the use of 2nd degree polynomial passing through the origin should be preferred.
Consider the following set of Pressure (mm Hg) versus Temperature (deg C) data:
The following operations need to be carried out with these data:
- Convert the temperature to K (by adding 273.15 to the value shown)
- Convert the pressure to kPa (by multiplying the value shown by 0.1333)
- Fit a fourth degree polynomial to the Pressure (dependent variable) vs. Temperature data.
The program to accomplish these tasks is shown below.
The Solution Report includes a Table listing the parameter values
and confidence intervals on these values.
For this particular problem the following results are shown.
The regression plot:
The Solution Report includes also the statistical metrics: R2, R2adj, root mean squared deviation and variance. A table displaying the observed (measured) y values, the predicted y values (ycalc) and the residuals (r = y - ycalc).
To fit a polynomial that passes through the origin the "polyfit"
command must also include the parameter "origin".
For example:
Multiple linear Regression
This PolymathPlus option will fit a linear function of the form:
where a0, a1, ..., an are regression parameters, to a set of N tabulated values of x1, x2, ..., xn (independent variables) versus y (dependent variable). Note that the number of data points must be greater than n+1 (thus N >= n+1). The program calculates the coefficients a0, a1, ..., an by minimizing the sum of squares of the deviations between the calculated and the data for y.
Use the mlinfit command to request a multiple linear regression fit. The arguments are the independent variables vector's names, followed by the independent vector name. Additional optional (last) argument is the string 'origin' which indicates that the regression curve should pass through the origin (thus a0 = 0).
Simple multiple linear regression example
The following data are for the wear of a bearing y that may be dependent upon x1 = oil viscosity and x2 = load data.:
In this example we compare the linear regression models that includes x1 and x2 as independent variables, with a model that includes only x1.
y = a0 + a1*x1 + a2*x2
The results obtained in this case are a0 = 360.836 (±118.076), a1 = -3.75246(±1.774), a2 = -0.084265(± 0.140313), R2 = 0.9835209 and σ2 = 159.1951.
To remove x2 from the regression model, the mlinfit statement is revised:
After this modification the following results are obtained: a0
= 292.784(±37.3385 ), a1 = -4.58727(±1.23994), R2 =
0.963462 and σ2 = 264.7302 .
Judging by the
R2
and
σ2
values, the
regression model that contains both x1 and x2
represents the data better. However, the confidence interval value of a2
shows that this parameter is not significantly different from zero, thus
removal of x2 from the model should be preferred
.
Considering the "vapor pressure" example to fit a regression model of the form:
The dependent variable can be defined by logP=log(P_kPa)
and the independent variables defined by OneonT=1/T_K
and logT=log(T_K)
.
Then mlinfit
can be used to find the parameter values.
The Solution Report includes a Table listing the parameter values and confidence intervals on these values. For this particular problem the following results are shown.
Nonlinear Regression
Nonlinear regression involves a general mathematical function (model) of the form:
where a0, a1, ..., an are regression parameters
to a set of N tabulated values of x1, x2, ..., xn
(independent variables) versus y (dependent variable). Note that the number of
data points must be greater than m + 1 (thus N >= m + 1).
Use the nlinfit command to request nonlinear regression fit. The argument is the nonlinear regression model: the dependent variable vector name on the left side of the "=" sign, the independent variable vectors names and the parameters on the right side. Initial estimates must be provided for all the parameter values using expressions of the form:
Fitting a nonlinear equation (Antoine) to the "vapor pressure example". The regression model is of the following form:
where P is pressure (mmHg) , T is temperature (deg C) and A, B and C
are parameters, need to be fitted to the "vapor pressure" example's
data.
Following is the program for finding the optimal parameter values
with nlinfit.
The optimal solution obtained is A = 5.76735, B = 677.094 and C = 153.885.
Regression Statistics
PolymathPlus provides statistical reports for the regression fit which assess the validity and accuracy of the regression. Each fitting variable has a 95% confidence interval. The confidence interval should be smaller than the absolute value of the variable for statistical validity.
In addition the following calculations are provided:
The following formulas calculate variables, standard deviation, and chi squared.
The following formulas calculate MAE, MSE, RMSE.
Variables and Expressions
The following objects compose a valid PolymathPlus math expression:
Object | Description |
---|---|
Number |
A number can be represented in decimal notation or engineering notation.
Engineering notation can be used to indicate powers of 10 using 'e' or 'E' For example, 0.123e-5 is the same as 0.123*10^(-5). Note that only the period "." is used as the decimal delimiter symbol and comma nor spaces must not be used to indicate digits grouping.
Sample valid
PolymathPlus
numbers:
Invalid PolymathPlus numbers: |
Variable Name |
Variable names must begin with an alphabetical character and can contain
alphabetic and numeric characters or underscore "_". Variable names are case-sensitive, i.e. 't' and 'T' are two different variables. Special characters such as $, &, #, @ etc. are not allowed.
Samples: |
Arithmetic Operator |
Returns the arithmetic operations of the binary components. For example '2+3' returns 5 The '^' symbol is used for exponentiation. The +, -, *, / symbols are used for addition, subtraction, multiplication, and division respectively. The precedence of operators is ^, (* or /), (+ or -) which is invoked working from left to right in an expression.
Samples: |
Function Name |
Various mathematical function names are available. Examples: sin, cos,
exp, ... The full list of available PolymathPlus functions is presented below.
Samples: |
Condition Operator |
These operators return "1" if the condition met, and "0" if the
condition does not meet. Examples: The expression '3>6' returns 0. The expression '4>=4' returns 1.
Valid conditional operators: |
Boolean Operator |
The Boolean operators return "1" if the condition is met, and "0" if the
condition is not met. Example: The expression '(2>3) or (1>0)' returns 1. The expression '1 and 0' returns 0.
Valid Boolean operators: |
If-Then-Else |
There are three case-insensitive keywords which compose the if-then-else
expression structure. The three keywords are: If, Then, Else.
Samples: |
A special if
statement is available, with the following syntax:
The parentheses are optional.
The condition may include the following operators: and, or (Boolean
operators), > (greater than), < (less than), >= (greater than or equal), <=
(less than or equal), == (equals).
The expressions may be any formula, including another if
statement (nested statements).
For example:
Available Functions
PolymathPlus supports a range of standard mathematical functions. Function names must be written in lowercase. For example:
Function Name | Description |
---|---|
abs | absolute value |
arccos | trigonometric inverse cosine with result in radians |
arccosec | trigonometric inverse cosecant with result in radians |
arccosech | inverse hyperbolic cosecant |
arcsech | inverse hyperbolic secant |
arccosh | inverse hyperbolic cosine |
arccotan | trigonometric inverse cotangent with result in radians |
arccotanh | inverse hyperbolic cotangent |
arcsec | trigonometric inverse secant with result in radians |
arcsin | trigonometric inverse sine with result in radians |
arcsinh | inverse hyperbolic sine |
arctan | trigonometric inverse tangent with result in radians |
arctanh | inverse hyperbolic tangent |
cbrt | cubic root |
cos | trigonometric cosine with argument in radians |
cosec | trigonometric cosecant with argument in radians |
cosech | hyperbolic cosecant |
cosh | hyperbolic cosine |
cotan | trigonometric cotangent with argument in radians |
coth | hyperbolic cotangent |
exp | exponential (e^x ) |
exp10 | exponential of 10 (10^x ) |
exp2 | exponential of 2 (2^x ) |
frac | fractional part |
int | integer part |
ln | natural logarithm to the base e |
log | logarithm to the base 10 |
psi | psi function |
round | rounded value |
sec | trigonometric secant with argument in radians |
sech | hyperbolic secant |
sign | returns + 1 or 0 or -1 |
sin | trigonometric sine with argument in radians |
sinh | hyperbolic sine |
sqrt | square root |
tan | trigonometric tangent with argument in radians |
tanh | hyperbolic tangent |
Settings and Hints
PolymathPlus allows custom tuning of solution algorithms, error tolerance, and basic adjustments to the output solution report. Default settings apply to all solution programs but can be overridden by program-specific hints.
Default Settings
Simply copy the relevant line, adjust its value, and include it in your program:
#@Report_show_header = False
#@Report_fix_digits = 10
#@Report_show_charts = True
#@chart_size = 428 300
Valid nonlinear equations solution method indexes are:
0=Fast-Newton 1=Safe-Newton 2=Safe-Broydn 3=Constrained
#@NLE_SOLUTION_METHOD_INDEX = 1
#@NLE_tol_x = 1E-07
#@NLE_tol_f = 1E-07
#@NLE_min_tol = 1E-07
#@NLE_eps = 1E-07
#@NLE_max_iter = 150
Valid differential equations solution method indexes are:
0=RKF45 1=RKF56 2=BS 3=Stiff 4=StiffBS
#@DEQ_SOLUTION_METHOD_INDEX = 0
#@DEQ_Intermediate_data_points = 50
#@DEQ_RKF_H = 1E-06
#@DEQ_RKF_TETOL = 1E-06
#@DEQ_EPS = 1E-05
#@DEQ_H1 = 0.001
#@DEQ_HMIN = 1E-08
Valid nonlinear regression solution method indexes are:
0=MRQMIN, 1=L-M
#@NLR_SOLUTION_METHOD_INDEX = 1
#@NLR_maxiter = 128
#@NLR_tol = 0.0001
Hints are pre-fixed with
#@
in the program file. The following sample DEQ problem has a hint line to propose the size of the chart on the solution report:
Hints for Linear Equations Programs
# | Hint syntax sample & Description |
---|---|
1 | #@Report_fix_digits = 8 |
Significant digits to display when presenting numbers | |
2 | #@Report_show_header = no |
Indicates whether a header text is displayed in the solution report Valid values are yes or no |
|
3 | #@Report_show_Settings = no |
Valid values are yes or no |
Hints for Nonlinear Equations Programs
# | Hint syntax sample & Description |
---|---|
1 | #@Report_fix_digits = 8 |
Significant digits to display when presenting numbers | |
2 | #@Report_show_header = no |
Indicates whether a header text is displayed in the solution report | |
3 | #@Report_show_charts = no |
Indicates whether charts should be displayed in the solution report Valid values are yes or no |
|
4 | #@Report_show_Settings = no |
Valid values are yes or no | |
5 | #@Chart_Size = 400 450 |
Indicates the size of the chart to be drawn in the report Values are Width; Height |
|
6 | #@NLE_SOLUTION_METHOD_INDEX = 1 |
Algorithm used to solve the NLE system. Valid method indexes are: 0 = Fast-Newton 1 = Safe-Newton 2 = Safe-Broydn 3 = Constrained |
|
7 | #@NLE_tol_x = 1E-07 |
8 | #@NLE_tol_f = 1E-07 |
9 | #@NLE_min_tol = 1E-07 |
10 | #@NLE_eps = 1E-07 |
11 | #@NLE_max_iter = 150 |
Hints for Differential Equations Programs
# | Hint syntax sample & Description |
---|---|
1 | #@Report_fix_digits = 8 |
Significant digits to display when presenting numbers | |
2 | #@Report_show_header = no |
Indicates whether a header text is displayed in the solution report | |
3 | #@Report_show_charts = no |
Indicates whether charts should be displayed in the solution report Valid values are yes or no |
|
4 | #@Report_show_Matlab = no |
Indicates whether a Matlab formatted problem should be displayed in the solution report Valid values are yes or no |
|
5 | #@Report_show_Settings = no |
Valid values are yes or no | |
6 | #@Report_Show_Intermediate_data_points = no |
Valid values are yes or no | |
7 | #@DEQ_Intermediate_data_points = 50 |
8 | #@DEQ_RKF_H = 1E-06 |
9 | #@DEQ_RKF_TETOL = 1E-06 |
10 | #@DEQ_EPS = 1E-05 |
11 | #@DEQ_H1 = 0.001 |
12 | #@DEQ_HMIN = 1E-08 |
13 | #@DEQ_SOLUTION_METHOD_INDEX = 3 |
DEQ solution method algorithm. Valid indexes are: 0 = RKF45 1 = RKF56 2 = BS 3 = Stiff 4 = StiffBS |
|
14 | #@Chart_Size = 400 450 |
Indicates the size of the chart to be drawn in the report Values are Width Height |
|
15 | #@Chart_Y_Curves = A B k3 k4 k5 |
Specifies the variable names, separated by space or semicolons, to include in the solution report. Invalid names will be ignored. You can divide the curves into up to three charts. Use the | symbol to specify which curves belong to each chart. For example #@Chart_Y_Curves = A B | k3 k4 k5
|
|
16 | #@chart_log_scales = 010 |
This hint specifies whether to use a logarithmic y-scale for each chart, with each digit corresponding to the nth chart. A value of 1 means a logarithmic y-scale is applied, while a value of 0 indicates a standard linear y-scale. In this example, the three digits represent the first, second, and third charts respectively, where the first and third charts use a linear scale, and the second chart uses a logarithmic y-scale. |
Hints for Regression Programs
# | Hint syntax sample & Description |
---|---|
1 | #@Report_fix_digits = 8 |
Significant digits to display when presenting numbers | |
2 | #@Report_show_header = no |
Indicates whether a header text is displayed in the solution report | |
3 | #@Report_show_data_points = no |
Display calculated datapoints table Valid values are yes or no |
|
4 | #@Report_show_settings = no |
Show program settings Valid values are yes or no |
|
5 | #@Report_show_charts = no |
Indicates whether charts should be displayed in the solution report Valid values are yes or no |
|
6 | #@Chart_Size = 400; 450 |
Indicates the size of the chart to be drawn in the report Values are Width; Height |
|
7 | #@NLR_SOLUTION_METHOD_INDEX = 1 |
Algorithm used to solve the NLR model. Valid method indexes are: 0 = MRQMIN 1 = L-M |
|
8 | #@NLR_maxiter = 64 |
9 | #@NLR_tol = 0.0001 |
👆