53
Instructions for Converting POLYMATH Solutions to Excel Worksheets - Instructions for Converting POLYMATH Solutions to Excel Worksheets - Introduction Introduction WHY EXCEL FOR NUMERICAL PROBLEM SOLVING? SPREADSHEETS ARE THE COMPUTATIONAL TOOLS MOST WIDELY USED BY CHEMICAL ENGINEERS. PROVIDING THE CAPABILITY FOR NUMERICAL PROBLEM SOLVING EXTENDS CONSIDERABLY THE COMPUTATIONAL POTENTIAL OF THE ENGINEER WHY USE A POLYMATH PREPROCESSOR ? THE MATHEMATICAL MODEL CAN BE MUCH EASIER AND FASTER CODED AND DEBUGGED USING POLYMATH. THE POLYMATH MODEL SERVES AS BASIS FOR THE SPREADSHEET MODEL WHERE THE VARIABLE NAMES ARE REPLACED BY THEIR ADDRESSES. IT ALSO SERVES AS AN EASY TO UNDERSTAND DOCUMENTATION OF THE MODEL

Instructions for Converting POLYMATH Solutions to Excel Worksheets

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Instructions for Converting POLYMATH Solutions to Excel Worksheets -Instructions for Converting POLYMATH Solutions to Excel Worksheets -IntroductionIntroduction

WHY EXCEL FOR NUMERICAL PROBLEM SOLVING?

SPREADSHEETS ARE THE COMPUTATIONAL TOOLS MOST WIDELY USED BYCHEMICAL ENGINEERS. PROVIDING THE CAPABILITY FOR NUMERICALPROBLEM SOLVING EXTENDS CONSIDERABLY THE COMPUTATIONALPOTENTIAL OF THE ENGINEER

WHY USE A POLYMATH PREPROCESSOR ?

THE MATHEMATICAL MODEL CAN BE MUCH EASIER AND FASTER CODED ANDDEBUGGED USING POLYMATH. THE POLYMATH MODEL SERVES AS BASIS FORTHE SPREADSHEET MODEL WHERE THE VARIABLE NAMES ARE REPLACED BYTHEIR ADDRESSES. IT ALSO SERVES AS AN EASY TO UNDERSTANDDOCUMENTATION OF THE MODEL

Page 2: Instructions for Converting POLYMATH Solutions to Excel Worksheets

CONVERTING POLYMATH SOLUTIONS TO EXCEL WORKSHEETSCONVERTING POLYMATH SOLUTIONS TO EXCEL WORKSHEETS

TYPES OF PROBLEMS DISCUSSEDTYPES OF PROBLEMS DISCUSSED

1 ONE NONLINEAR ALGEBRAIC EQUATION – GOAL SEEK – SLIDES 3-9

2 SYSTEMS OF NONLINEAR ALGEBRAIC EQUATIONS – SOLVER – SLIDES 10-14

3 ODE – INITIAL VALUE PROBLEMS – 4TH ORDER EXPLICIT RK – SLIDES 15-24

4 ODE – BOUNDARY VALUE – EXPLICIT EULER + GOAL SEEK – SLIDES 25-29

5 DAE – INITIAL VALUE PROBLEMS – IMPLICIT EULER – SLIDES 30-36

6 PDE – INITIAL VALUE - METHOD OF LINES – EXPLICIT EULER – SLIDES 37-40

7 MULTIPLE LINEAR REGRESSION – LINEST – SLIDES 41-45

8 POLYNOMIAL REGRESSION – LINEST – SLIDES 46-49

9 MULTIPLE NONLINEAR REGRESSION – SOLVER – SLIDES 50-53

Page 3: Instructions for Converting POLYMATH Solutions to Excel Worksheets

One Nonlinear Algebraic Equation Instructions for Conversion (1)One Nonlinear Algebraic Equation Instructions for Conversion (1)

To obtain a basic solution of a system containing one implicit nonlinear algebraic equation andseveral explicit equations the POLYMATH equations should be converted to Excel formulasand then the "Goal Seek" tool can be used. In order to obtain a well documented Excelworksheet, which can be easily modified for parametric runs it is recommended to carry out theconversion in the following steps:

1. Copy the implicit equation and the ordered explicit equations from the POLYMATHsolution report.

2. Paste the equations into an Excel worksheet; remove the text and the equation numbers.

3. Rearrange the equations in the order: constant definitions, functions of the constants,parameter definitions, unknown, explicit functions of the unknown and implicit functionof the unknown.

Page 4: Instructions for Converting POLYMATH Solutions to Excel Worksheets

One Nonlinear Algebraic EquationOne Nonlinear Algebraic Equation

Instructions for Conversion (2)Instructions for Conversion (2)

4. Copy the right hand side of the equations into the adjacent cell and replace the variable namesby variable addresses. Note that "If" statements and some functions may require additionalrewriting and/or rearrangement. Use absolute addressing for the constants and the functions ofconstant and relative addressing for the unknown and its functions (Note that pressing F4converts selected reference from relative to absolute). In the cell adjacent to the unknown put itsinitial estimate.

5. Use the "Goal Seek" tool to set the value of the cell containing the implicit function of theunknown at zero while changing the value in the cell of the unknown..

Page 5: Instructions for Converting POLYMATH Solutions to Excel Worksheets

One Nonlinear Algebraic EquationOne Nonlinear Algebraic Equation

Ordered POLYMATH FileOrdered POLYMATH File

The use of this procedure is demonstrated in reference to Demo 2.

Nonlinear equations [1] f(V) = (P+a/(V^2))*(V-b)-R*T = 0 Explicit equations [1] P = 56 [2] R = 0.08206 [3] T = 450 [4] Tc = 405.5 [5] Pc = 111.3 [6] Pr = P/Pc [7] a = 27*(R^2*Tc^2/Pc)/64 [8] b = R*Tc/(8*Pc) [9] Z = P*V/(R*T)

Page 6: Instructions for Converting POLYMATH Solutions to Excel Worksheets

One Nonlinear Algebraic EquationOne Nonlinear Algebraic Equation

Excel FormulasExcel Formulas

CBA

=($C$5+$C$11/(C13^2))*(C13-$C$12)-$C$6*$C$7

f(V) = (P+a/(V^2))*(V-b)-R*T = 015

=$C$5*C13/($C$6*$C$7) Z = P*V/(R*T)Functions of theunknown

14

0.7 VUnknown13

=$C$6*$C$8/(8*$C$9) b = R*Tc/(8*Pc)12

=27*($C$6^2*$C$8^2/$C$9)/64 a = 27*(R^2*Tc^2/Pc)/6411

=$C$5/$C$9 Pr = P/PcFunctions of theconstants

10

=111.3 Pc = 111.39

=405.5 Tc = 405.58

=450 T = 4507

=0.08206 R = 0.082066

=56 P = 56Constants5

4

Equations3

Page 7: Instructions for Converting POLYMATH Solutions to Excel Worksheets

One Nonlinear Algebraic Equation SolutionOne Nonlinear Algebraic Equation Solution

To solve the nonlinear equation in cell C15 "Goal Seek" is used to set the value in this cellat zero while changing the contents of cell C13.

8.4999E-075.85576f(V) = (P+a/(V^2))*(V-b)-R*T = 015

0.871831.06155 Z = P*V/(R*T)14

0.574890.7V13

0.037370.03737 b = R*Tc/(8*Pc)12

4.196954.19695 a = 27*(R^2*Tc^2/Pc)/6411

0.503140.50314 Pr = P/Pc10

111.3111.3 Pc = 111.39

405.5405.5 Tc = 405.58

450450 T = 4507

0.082060.08206 R = 0.082066

5656 P = 565

4

SolutionInitial values 3

Page 8: Instructions for Converting POLYMATH Solutions to Excel Worksheets

One Nonlinear Algebraic EquationOne Nonlinear Algebraic Equation

Modifying the Equation SetModifying the Equation Set

The example is next solved for Pr = 1, 2, 4, 10 and 20. To achieve this, the parameter Tr and itsfunction P=Pr*Pc are added to the equation set and the cells containing the unknown and itsfunctions are copied and modified as necessary.

CBA

=(C24+$C$11/(C25^2))*(C25-$C$12)-$C$6*$C$7

f(V) = (P+a/(V^2))*(V-b)-R*T = 0 27

=C24*C25/($C$6*$C$7) Z = P*V/(R*T)Functions of theunknown

26

0.233508696752435VUnknown25

=C23*$C$9P = Pr*PcFunction of theparameter

24

1PrParameter23

Page 9: Instructions for Converting POLYMATH Solutions to Excel Worksheets

One Nonlinear Algebraic EquationOne Nonlinear Algebraic Equation

Complete solution setComplete solution set

To obtain the solution for other values of Pr cells 24 – 27 of column C are copied and thevalue of Pr entered in row 23. "Goal Seek" is applied separately to every column containinga different Pr value.

6.962E-096.184E-082.208E-067.604E-073.940E-06f(V) = (P+a/(V^2))*(V-b)-R*T = 0

2.783481.533410.731260.465780.70381 Z = P*V/(R*T)

0.046180.050880.060650.077270.23351V

22261113445.2222.6111.3P = Pr*Pc

2010421Pr

Page 10: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Systems of Nonlinear Algebraic EquationsSystems of Nonlinear Algebraic Equations

Instructions for Conversion (1)Instructions for Conversion (1)

To obtain a basic solution of a system containing several implicit nonlinear algebraic equationsthe POLYMATH equations are converted to Excel formulas and then the "Solver" tool isused. The recommended steps for conversion are:

1. Copy the implicit equations and the ordered explicit equations from the POLYMATHsolution report.

2. Paste the equations into an Excel worksheet; remove the text and the equation numbers.

3. Rearrange the equations in the order: constant definitions, functions of the constants,parameter definitions, unknowns, explicit functions of the unknowns and implicit functionsof the unknowns.

4. Add an equation with the sum of squares of the implicit functions.

Page 11: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Systems of Nonlinear Algebraic EquationsSystems of Nonlinear Algebraic Equations

Instructions for Conversion (2)Instructions for Conversion (2)

5. Copy the right hand side of the equations into the adjacent cell and replace the variablenames by variable addresses. Use absolute addressing for the constants and the functions ofconstant and relative addressing for the unknowns and functions of the unknowns. In the celladjacent to the unknowns put initial estimates.

6. Use the "Solver" tool to set the value of the cell containing the sum of squares of theimplicit functions of the unknowns at zero (or minimizing its value) while changing the valuesin the cells of the unknowns.

Page 12: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Systems of Nonlinear Algebraic EquationsSystems of Nonlinear Algebraic Equations

Ordered POLYMATH FileOrdered POLYMATH File

The use of this procedure is demonstrated in reference to Demo 5

Nonlinear equations [1] f(CD) = CC*CD-KC1*CA*CB = 0 [2] f(CX) = CX*CY-KC2*CB*CC = 0 [3] f(CZ) = CZ-KC3*CA*CX = 0 Explicit equations [1] KC1 = 1.06 [2] CY = CX+CZ [3] KC2 = 2.63 [4] KC3 = 5 [5] CA0 = 1.5 [6] CB0 = 1.5 [7] CC = CD-CY [8] CA = CA0-CD-CZ [9] CB = CB0-CD-CY

Page 13: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Systems of Nonlinear Algebraic Equations Excel FormulasSystems of Nonlinear Algebraic Equations Excel Formulas

=C12-$C$9*C15*C11f(CZ) = CZ-KC3*CA*CX = 0 19

=C17^2+C18^2+C19^2sum=f(CD)^2+f(CX)^2+f(CZ)^2Sum of squares of errors20

=C11*C13-$C$8*C16*C14f(CX) = CX*CY-KC2*CB*CC = 0 18

=C14*C10-$C$7*C15*C16f(CD) = CC*CD-KC1*CA*CB = 0 17

=$C$6-C10-C13CB = CB0-CD-CY 16

=$C$5-C10-C12CA = CA0-CD-CZ 15

=C10-C13CC = CD-CY 14

=C11+C12CY = CX+CZFunctions of the unknowns13

0CZ 12

0CX 11

0CDUnknowns10

5KC3 = 5 9

2.63KC2 = 2.63 8

1.06KC1 = 1.06 7

1.5CB0 = 1.5 6

1.5CA0 = 1.5Constants5

Equations 4

CBA

Page 14: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Systems of Nonlinear Algebraic Equations Excel FormulasSystems of Nonlinear Algebraic Equations Excel Formulas

The "Solver" tool is used to minimize the sum of squares of errors in cell C20 by settingC20 as "target cell" and searching for its minimal value by changing cells C10, C11 and C12.

1.0741E-135.68823sum=f(CD)^2+f(CX)^2+f(CZ)^2-2.9923E-070f(CZ) = CZ-KC3*CA*CX = 0-1.3358E-070f(CX) = CX*CY-KC2*CB*CC = 05.1760E-09-2.385f(CD) = CC*CD-KC1*CA*CB = 0

0.242901.5CB = CB0-CD-CY0.420691.5CA = CA0-CD-CZ0.153570CC = CD-CY0.551770CY = CX+CZ0.373980CZ0.177790CX0.705330CD

55KC3 = 52.632.63KC2 = 2.631.061.06KC1 = 1.061.51.5CB0 = 1.51.51.5CA0 = 1.5

SolutionInitial values

Page 15: Instructions for Converting POLYMATH Solutions to Excel Worksheets

ODE ODE –– Initial Value Problems Initial Value Problems

TheThe Runge Runge--KuttaKutta Method Method

There are no tools in Excel to solve differential equations so the solution algorithm must bebuild into the solution worksheet. In this example a fixed step size, explicit, fourth-orderRunge-Kutta algorithm is used. The system of N first-order ODE for the functions

is written :

(1)

The fourth-order Runge-Kutta formula is written:

(2)

This formula advances a solution from xn to

Niyi ,,1, K=

),,,,()(

1 Nii yyxfdx

xdyK= Ni ,,1 K=

)22(61

),(

)2

,2

(

)2

,2

(

),(

43211

34

23

12

1

kkkkyy

kyhxhfk

kyhxhfk

kyhxhfk

yxhfk

nn

nn

nn

nn

nn

++++=

++=

++=

++=

=

+

hxx nn +≡+1

Page 16: Instructions for Converting POLYMATH Solutions to Excel Worksheets

ODE ODE –– Initial Value Problems Instructions for Conversion (1) Initial Value Problems Instructions for Conversion (1)

Apply the Runge-Kutta algorithm to the system of first-order, ODE carry out the conversionfrom the POLYMATH file to the Excel spreadsheet in the following steps:

1.Copy the differential equation and the ordered explicit algebraic equations from thePOLYMATH solution report.

2. Paste the equations into an Excel worksheet; remove the text and the equation numbers.

3. Put the parameters: final value of the independent variable and integration step-size (h) inthe first cells of the worksheet. Rearrange the equations in the order: constant definitions,functions of the constants, independent variable, dependent variables, explicit functions ofthe variables and differential equations.

Page 17: Instructions for Converting POLYMATH Solutions to Excel Worksheets

ODE ODE –– Initial Value Problems Initial Value Problems

Instructions for Conversion (2)Instructions for Conversion (2)

4. Copy the right hand side of the equations into the adjacent cell and replace the variable namesby variable addresses. Use absolute addressing for the constants and the functions of constantand relative addressing for the variables and functions of the variables. In the cell adjacent tothe variables put their initial values.

5. Copy the section starting with the independent variable up to the end of the equation set andpaste this section three times below, to obtain the values of k2, k3 and k4. Change the equationsas needed to reflect the change in the variable values, as shown in Equation (2).

6. In the next column write the equations to calculate the advanced values of the independent anddependent variables.

7. Copy and paste the columns (or rows) as many time as needed in order to reach the finalvalue of the independent variable.

Page 18: Instructions for Converting POLYMATH Solutions to Excel Worksheets

ODE ODE –– Initial Value Problems Initial Value Problems

Ordered POLYMATH FileOrdered POLYMATH File

The use of this procedure is demonstrated in reference to Demo 9.

Differential equations as entered by the user [1] d(T1)/d(t) = (W*Cp*(T0-T1)+UA*(Tsteam-T1))/(M*Cp) [2] d(T2)/d(t) = (W*Cp*(T1-T2)+UA*(Tsteam-T2))/(M*Cp) [3] d(T3)/d(t) = (W*Cp*(T2-T3)+UA*(Tsteam-T3))/(M*Cp)Explicit equations as entered by the user [1] W = 100 [2] Cp = 2.0 [3] T0 = 20 [4] UA = 10. [5] Tsteam = 250 [6] M = 1000

Page 19: Instructions for Converting POLYMATH Solutions to Excel Worksheets

ODE ODE –– Initial Value Problems Excel Formulas (1) Initial Value Problems Excel Formulas (1)

=$C$6*($C$7*$C$8*(C14-C15)+$C$10*($C$11-C15))/($C$12*$C$8)

k12=h*d(T2)/d(t)=h*(W*Cp*(T1-T2)+UA*(Tsteam-T2))/(M*Cp) 18

=$C$6*($C$7*$C$8*($C$9-C14)+$C$10*($C$11-C14))/($C$12*$C$8)

k11=h*d(T1)/d(t)=h*(W*Cp*(T0-T1)+UA*(Tsteam-T1))/(M*Cp)Differential equations17

20T3 1620T2 1520T1Dependent variables140tIndependent variable13=1000M=1000 12=250Tsteam=250 11=10UA=10. 10=20T0=20 9=2Cp=2.0 8=100W=100Constants7=($C$5-$C$13)/200hIntegration step size6200tf=200Final value (ind. Var.)5Equations/valuesDefinitions 4

CBA

Page 20: Instructions for Converting POLYMATH Solutions to Excel Worksheets

ODE ODE –– Initial Value Problems Initial Value Problems

Excel Formulas (2)Excel Formulas (2)

=$C$6*($C$7*$C$8*(C27-C28)+$C$10*($C$11-C28))/($C$12*$C$8)

k3331

=$C$6*($C$7*$C$8*(C26-C27)+$C$10*($C$11-C27))/($C$12*$C$8)

k3230

=$C$6*($C$7*$C$8*($C$9-C26)+$C$10*($C$11-C26))/($C$12*$C$8)

k3129

=C16+$C$6*C25/2T3+k23/228

=C15+$C$6*C24/2T2+k22/227

=C14+$C$6*C23/2T1+k21/226

=$C$6*($C$7*$C$8*(C21-C22)+$C$10*($C$11C22))/($C$12*$C$8)

k2325

=$C$6*($C$7*$C$8*(C20-C21)+$C$10*($C$11-C21))/($C$12*$C$8)

k2224

=$C$6*($C$7*$C$8*($C$9-C20)+$C$10*($C$11-C20))/($C$12*$C$8)

k2123

=C16+$C$6*C19/2T3+k13/222

=C15+$C$6*C18/2T2+k12/221

=C14+$C$6*C17/2T1+k11/220

CBA

Page 21: Instructions for Converting POLYMATH Solutions to Excel Worksheets

ODE ODE –– Initial Value Problems Initial Value Problems

Excel Formulas (3)Excel Formulas (3)

In column D the solution is advanced from xn to hxx nn +≡+1

=$C$6*($C$7*$C$8*(C33-C34)+$C$10*($C$11-C34))/($C$12*$C$8)

k4337

=$C$6*($C$7*$C$8*(C32-C33)+$C$10*($C$11-C33))/($C$12*$C$8)

k4236

=$C$6*($C$7*$C$8*($C$9-C32)+$C$10*($C$11-C32))/($C$12*$C$8)

k4135

=C16+$C$6*C31T3+k3334

=C15+$C$6*C30T2+k3233

=C14+$C$6*C29T1+k3132

CBA

=C16+(1/6)*(C19+2*C25+2*C31+C37)20T3 16

=C15+(1/6)*(C18+2*C24+2*C30+C36)20T2 15

=C14+(1/6)*(C17+2*C23+2*C29+C35)20T1Dependent variables14

=C13+$C$60tIndependent variable13

DCBA

Page 22: Instructions for Converting POLYMATH Solutions to Excel Worksheets

ODE ODE –– Initial Value Problems Initial Value Problems

Results for Results for t=1 min and t=80 mint=1 min and t=80 min (1) (1)

1.0603E-021.144091.15k13

2.3274E-031.138911.15k12

2.5860E-041.035371.15k11Differential equations

51.1930321.1470820T3

41.3587121.1453220T2

30.9499221.0916820T1Dependent variables

8010tIndependent variable

1000M=1000

250Tsteam=250

10UA=10.

20T0=20

2Cp=2.0

100W=100Constants

1hIntegration step size

200tf=200Final value (ind. var.)

Equations/valuesDefinitions

Page 23: Instructions for Converting POLYMATH Solutions to Excel Worksheets

ODE ODE –– Initial Value Problems Initial Value Problems

Results for t=1 min and t=80 min (2)Results for t=1 min and t=80 min (2)

9.7559E-031.137171.14398k432.1185E-031.118801.13913k422.3280E-040.932071.03526k4151.2032122.2878121.14713T3+k3341.3609322.2739121.14426T2+k3230.9501622.0755521.09279T1+k31

1.0180E-021.140731.14713k332.2232E-031.128591.14426k322.4574E-040.983871.09279k3151.1981121.7175720.57356T3+k23/241.3598221.7107620.57356T2+k22/230.9500421.5821920.54481T1+k21/2

1.0162E-021.140971.147125k232.2181E-031.130891.147125k222.4502E-040.981021.089625k2151.1983321.7191320.575T3+k13/241.3598721.7147720.575T2+k12/230.9500521.6093720.575T1+k11/2

Page 24: Instructions for Converting POLYMATH Solutions to Excel Worksheets

ODE ODE –– Initial Value Problems Initial Value Problems

Plot of the resultsPlot of the results

H eat E xch an g e in a S eries o f T an ks

20

25

30

35

40

45

50

55

0 50 100

Tim e (m in)

Temperature (deg. C

T 1 (t)

T2(t)

T3(t)

Page 25: Instructions for Converting POLYMATH Solutions to Excel Worksheets

ODE ODE –– Boundary Value Problems Boundary Value Problems

Solution MethodSolution Method

There are no tools in Excel to solve differential equations so the solution algorithm must bebuild into the solution worksheet. In this example a fixed step size, explicit, Euler algorithmis used. After setting up the worksheet for integrating the differential equations the "GoalSeek" (for the case of one boundary value) or the "Solver" (for the case of several boundaryvalues) is used for converging to the proper initial values.The formula for the Euler method is

(3)

This formula advances a solution from xn to

Steps of the Solution.

1. Copy the differential equation and the ordered explicit algebraic equations from thePOLYMATH solution report.

2. Paste the equations into an Excel worksheet; remove the text and the equation numbers.

),(1 nnnn yxhfyy +=+

hxx nn +≡+1

Page 26: Instructions for Converting POLYMATH Solutions to Excel Worksheets

ODE ODE –– Boundary Value Problems Boundary Value Problems

Steps of the SolutionSteps of the Solution

3. Put the parameters: final value of the independent variable and integration step-size (h)in the first cells of the worksheet. Rearrange the equations in the order: constant definitions,functions of the constants, independent variable, dependent variables, explicit functionsof the variables and differential equations.

4. Copy the right hand side of the equations into the adjacent cell and replace the variablenames by variable addresses. In the cell adjacent to the variables put their initial values. If theinitial value is not known put initial estimates, instead.

5. In the next column write the equations to calculate the advanced values of the variablesusing Equation 3.

6. Copy and paste the columns as many times as needed in order to reach the final value ofthe independent variable.

7. Use the "Goal Seek" (for the case of one boundary value) or the "Solver" (for the case ofseveral boundary values) to converge to the desired final value of the variables whilechanging their initial values.

Page 27: Instructions for Converting POLYMATH Solutions to Excel Worksheets

ODE ODE –– Boundary Value Problems Boundary Value Problems

POLYMATH File and Excel FormulasPOLYMATH File and Excel Formulas

The use of this procedure is demonstrated in reference to Demo 8.

Differential equations as entered by the user [1] d(CA)/d(z) = y [2] d(y)/d(z) = k*CA/DAB Explicit equations as entered by the user [1] k = 0.001 [2] DAB = 1.2E-9

Page 28: Instructions for Converting POLYMATH Solutions to Excel Worksheets

=$C$8*D11/$C$9=$C$8*C11/$C$9f2=d(y)/d(z) = k*CA/DAB 14

=D12=C12f1=d(CA)/d(z) = yDifferential equations13

=C12+$C$7*C14-150y 12

=C11+$C$7*C130.2CADependent variables11

=C10+$C$70zIndependent variable10

0.0000000012DAB = 1.2E-9 9

0.001 k = 0.001Constants8

=(C6-C10)/100hIntegration step-size7

0.001zf=0.001Final value ind.var.6

5

Equations/valuesDefinitions 4

DCBA

Page 29: Instructions for Converting POLYMATH Solutions to Excel Worksheets

ODE ODE –– Boundary Value Problems Boundary Value ProblemsResults at z = 0, 0.00001 and 0.001 mResults at z = 0, 0.00001 and 0.001 m

1. Initial estimate: y = -150

2. After using of the "Goal Seek" tool to set the value of y(0.001) at zero while changing y(0).

9.7563E+04165416.6671.6667E+05f2=d(y)/d(z) =k*CA/DAB

-26.052-148.333-150f1=d(CA)/d(z) = yDifferential equations

-26.052-148.333-150y

0.117080.19850.2CADependent variables

0.0010.000010zIndependent variable

1.1475E+05-130.2471.6667E+05f2=d(y)/d(z) =k*CA/DAB

-7.53E-140.13770-131.913f1=d(CA)/d(z) = yDifferential equations-7.53E-140.19868-131.913y 0.137700.0010.2CADependent variables0.0010.000010zIndependent variable

Page 30: Instructions for Converting POLYMATH Solutions to Excel Worksheets

DAE DAE –– Initial Value Problems Initial Value Problems

Solution MethodSolution Method

There are no tools in Excel to solve differential equations so the solution algorithm must be buildinto the solution worksheet. In this example a fixed step size, implicit, Euler algorithm is used.Using this method the differential equations are converted into nonlinear algebraic equations.Thus, in each integration step a system of nonlinear algebraic equations is solved using the"Solver" tool. The formula for the implicit Euler method is

(4)

This formula advances a solution from xn-1 to for n>1.

0)},(),({2 111 =

++−= −−− nnnnnnn yxfyxfhyyF

hxx nn +≡ −1

Page 31: Instructions for Converting POLYMATH Solutions to Excel Worksheets

DAE DAE –– Initial Value Problems Initial Value Problems

Steps of the Solution (1)Steps of the Solution (1)

1. Copy the differential equations and the ordered explicit algebraic equations from thePOLYMATH solution report.

2. Paste the equations into an Excel worksheet; remove the text and the equation numbers.

3. Put the parameters: final value of the independent variable and integration step-size (h) inthe first cells of the worksheet. Rearrange the equations in the order: constant definitions,functions of the constants, independent variable, dependent variables, explicit functions ofthe variables, differential equations and implicit algebraic equations.

4. Add an equation with the sum of squares of the implicit functions (the algebraic equationsand the implicit Euler method representation of the differential equations).

Page 32: Instructions for Converting POLYMATH Solutions to Excel Worksheets

DAE DAE –– Initial Value Problems Initial Value Problems

Steps of the Solution (2)Steps of the Solution (2)

5. Copy the right hand side of the equations into the adjacent cells and replace the variablenames by variable addresses. Use absolute addressing for the constants and the functions ofconstant and relative addressing for the variables and functions of the variables. In the celladjacent to the variables put their initial values. In the cell containing the sum of squares ofthe function values include only the functions associated with the implicit algebraic equations.

6. Use the "Solver" (or "Goal Seek" tools) to find the initial values of the unknownsassociated with the implicit algebraic equations.

7. In the next column write the equations to calculate the advanced values of the independentand dependent variables.

8. From this point on the columns can be copied and pasted, as many time as needed to reachthe final value of the independent variable. The "Solver" tool must be applied on thecolumns sequentially, to solve the system of nonlinear algebraic equations for each step

Page 33: Instructions for Converting POLYMATH Solutions to Excel Worksheets

DAE DAE –– Initial Value Problems Initial Value Problems

POLYMATH FilePOLYMATH File

The use of this procedure is demonstrated in reference to Demo 11 The differential equationsand the ordered explicit algebraic equations as copied from the POLYMATH solution reportare the following.

Differential equations as entered by the user [1] d(L)/d(x2) = L/(k2*x2-x2) [2] d(T)/d(x2) = Kc*err Explicit equations as entered by the user [1] Kc = 0.5e6 [2] k2 = 10^(6.95464-1344.8/(T+219.482))/(760*1.2) [3] x1 = 1-x2 [4] k1 = 10^(6.90565-1211.033/(T+220.79))/(760*1.2) [5] err = (1-k1*x1-k2*x2)

Page 34: Instructions for Converting POLYMATH Solutions to Excel Worksheets

DAE DAE –– Initial Value Problems Excel formulas Initial Value Problems Excel formulas

In the next column (column D) the definition of the independent variable is changed to:=C8+$C$7 and the definition of the sum of squares of errors ischanged to: =(D9-(C9+($C$7/2)*(C14+D14)))^2+D15^2 .

[Ln-(Ln-1+h/2(f1n+f1n-1))]^2+f2n+1^2Sum of squares oferrors16

=(1-C12*C11-C13*C8)f2=f(T)=(1-k1*x1-k2*x2)=0 15= C9/(C13*C8-C8)f1=d(L)/d(x2) = L/(k2*x2-x2)Differential equations14

= 10^(6.95464-1344.8/(C10+219.482))/(760*1.2)

k2 = 10^(6.95464-1344.8/(T+219.482))/(760*1.2) 13

= 10^(6.90565-1211.033/(C10+220.79))/(760*1.2)

k1 = 10^(6.90565-1211.033/(T+220.79))/(760*1.2) 12

= 1-C8x1 = 1-x2Explicit equations1195T= 10100L=Dependent variables90.4x2Independent variable8=($C$6-$C$8)/20hIntegration step-size70.8x2(f)=Final value ind.var.6

Equations/valuesDefinitions 5CBA

Page 35: Instructions for Converting POLYMATH Solutions to Excel Worksheets

DAE DAE –– Initial Value Problems Initial Value Problems

Results for x2 = 0.4 and 0.42Results for x2 = 0.4 and 0.42

Results obtained by applying "Goal Seek" to set cell C15 at zero while changing the initialtemperature (cell C10) and subsequently applying the "Solver" tool to minimize the value incell D16 while changing the contents of cells D9 and D10.

4.4521E-08[Ln-(Ln-1+h/2(f1n+f1n-1))]^2+f2n+1^2Sum of squares of errors

-2.1100E-046.8122E-05f2=f(T)=(1-k1*x1-k2*x2)=0

-467.601-534.754f1=d(L)/d(x2) = L/(k2*x2-x2)Differential equations

0.541850.53250k2 = 10^(6.95464-1344.8/(T+219.482))/(760*1.2)

1.33211.3116k1 = 10^(6.90565-1211.033/(T+220.79))/(760*1.2)

0.580.6x1 = 1-x2Explicit equations96.14295.583T= 89.976100L=Dependent variables0.420.4x2Independent variable

0.02hIntegration step-size 0.8x2(f)=Final value ind.var.

Page 36: Instructions for Converting POLYMATH Solutions to Excel Worksheets

DAE DAE –– Initial Value Problems Initial Value Problems

Results for x2 = 0.8Results for x2 = 0.8

Column D is copied and pasted as many time as necessary to reach the final value of x2 (= 0.8).The "Solver" tool is applied sequentially, for every column to minimize the value in row 16.

5.1713E-07[Ln-(Ln-1+h/2(f1n+f1n-1))]^2+f2n+1^2Sum of squares of errors

-6.4625E-04f2=f(T)=(1-k1*x1-k2*x2)=0

3.1544E-04f1=d(L)/d(x2) = L/(k2*x2-x2)Differential equations

0.78634k2 =

1.8579k1 =

0.2x1 = 1-x2Explicit equations

108.595T=

14.006L=Dependent variables

0.8x2Independent variable

Page 37: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Partial Differential Equations Excel Formulas for Demo 12 (1)Partial Differential Equations Excel Formulas for Demo 12 (1)

The system of PDEs is converted into a system of first order ODEs using the method of lines.Explicit Euler's method is used for solution.

=(4*D$22-D$21)/3=(4*C$22-C$21)/3T11 = (4*T10-T9)/3 23=C22+($F$29-$F$28)*C32100T10 22=C21+($F$29-$F$28)*C31100T9 21=C20+($F$29-$F$28)*C30100T8 20=C19+($F$29-$F$28)*C29100T7 19=C18+($F$29-$F$28)*C28100T6 18=C17+($F$29-$F$28)*C27100T5 17=C16+($F$29-$F$28)*C26100T4 16=C15+($F$29-$F$28)*C25100T3 15=C14+($F$29-$F$28)*C24100T2Variables14=C13+$C$80tIndependent Variable13 =C10/C11^2alpha/deltax^2 12 0.1deltax = .10 11 0.00002alpha = 2.e-5 10 0T1 = 0Constants9 =(C7-C13)/200hIntegration Step-size8 6000tf=6000Final value ind.var.7 Equations/valuesDefinitions 6

DCBA

Page 38: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Partial Differential EquationsPartial Differential Equations

Excel Formulas for Demo 12 (2)Excel Formulas for Demo 12 (2)

=$C$12*($P28-2*$O28+$N28)f9=d(T10)/d(t) = alpha/deltax^2*(T11-2*T10+T9) 32

=$C$12*($O28-2*$N28+$M28)f8=d(T9)/d(t) = alpha/deltax^2*(T10-2*T9+T8) 31

=$C$12*($N28-2*$M28+$L28)f7=d(T8)/d(t) = alpha/deltax^2*(T9-2*T8+T7) 30

=$C$12*($M28-2*$L28+$K28)f6=d(T7)/d(t) = alpha/deltax^2*(T8-2*T7+T6) 29

=$C$12*($L28-2*$K28+$J28)f5=d(T6)/d(t) = alpha/deltax^2*(T7-2*T6+T5) 28

=$C$12*($K28-2*$J28+$I28)f4=d(T5)/d(t) = alpha/deltax^2*(T6-2*T5+T4) 27

=$C$12*($J28-2*$I28+$H28)f3=d(T4)/d(t) = alpha/deltax^2*(T5-2*T4+T3) 26

=$C$12*($I28-2*$H28+$G28)f2=d(T3)/d(t) = alpha/deltax^2*(T4-2*T3+T2) 25

=$C$12*($H28-2*$G28+$C$9)f1=d(T2)/d(t) = alpha/deltax^2*(T3-2*T2+T1)

Differentialequations24

CBA

Column D for this section is obtained by copying and pasting the same section in column C.To obtain the complete solution column D is copied and pasted as many times as needed forreaching the final time.

Page 39: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Partial Differential EquationsPartial Differential Equations

Results for Results for t=0, 30 and 6000 mint=0, 30 and 6000 min

91.6912100100T11 = (4*T10-T9)/390.8270100100T1088.2343100100T983.8125100100T877.4300100100T768.9780100100T658.4307100100T545.8980100100T431.6589100100T316.163294100T2

6000300t 2.00E-03alpha/deltax^2 0.1deltax = .10 2.00E-05alpha = 2.e-5 0T1 = 0 30h 6000tf=6000 Equations/valuesDefinitions

Page 40: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Partial Differential EquationsPartial Differential Equations

Plot of Some Results for Demo 12Plot of Some Results for Demo 12

T em perature P rofiles for a O ne-D im entional S lab

0

20

40

60

80

100

120

0 2000 4000 6000

T im e (s)

Temperature (C)

T2

T3

T4

T5

Page 41: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Multiple Linear RegressionMultiple Linear Regression

Copying the Data from POLYMATHCopying the Data from POLYMATHIn this demonstration Riedel's equation is fitted to the data of Demo 6.

Page 42: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Multiple Linear RegressionMultiple Linear Regression

Pasting the Data into Excel and Adding TitlesPasting the Data into Excel and Adding Titles

2.8808141.25E+052.54808220.0028308611

2.602061.11E+052.52342130.0029962510

2.3010399445.622.49879280.003171089

289550.562.47603420.003341698

1.77815183261.12.46022110.00346567

1.6020678820.562.44831980.003561896

1.3010373197.32.43224750.003696175

168460.722.41772070.00382194

0.6989764287.62.40406360.0039443

055908.62.37373930.004229222

logPT2logTTrec1

DCBA

Page 43: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Multiple Linear RegressionMultiple Linear Regression

Using the LINEST FunctionUsing the LINEST Function

The LINEST function puts the full set of results in an area that includes 5 rows and numberof columns as the number of the parameters.

For this problem mark an area of 5 rows and 4 columns. Type in LINEST(D2:D11, A2:C11,TRUE,TRUE) and press CONTROL+SHIFT+ENTER to enter this formula into all themarked cells.

Note that the range D2:D11 is the range where the dependent variable values are stored, therange A2:C11 is the range where the independent variable values are stored, the first logicalvariable TRUE (or the number 1) indicates that the parameter a0 cannot be assumed to be zeroand the second logical variable TRUE indicates that a matrix of regression statistics shouldalso be returned.

It is permitted to mark a one-, two-, three-, four-, or five-row array depending on the amount ofinformation desired.

The results obtained do not include any labeling and labeling should be added manually.

Page 44: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Multiple Linear RegressionMultiple Linear Regression

Results (1)Results (1)

For obtaining the results reported by POLYMATH the first three rows are significant. Thefirst row (coeff.s) contains the values of the parameters. The second row (std. dev. S.) containsthe standard deviation of the parameters. These values can be multiplied by the appropriatevalue from the t distribution to obtain the 95% confidence intervals. The square of thestandard error in y (SE y) is the variance as reported by POLYMATH.

#N/A#N/A0.0017777.1446SS(reg),SS(resid)

#N/A#N/A68042.39F, df

#N/A#N/A0.0172080.99975R2, SE (y)

63.9211984.9623.877062.0439E-05std.dev.s

216.721-9318.66-75.74824.4446E-05coeff.s

a0a1a2a3

Page 45: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Multiple Linear RegressionMultiple Linear Regression

Variance and Confidence intervals and ResidualsVariance and Confidence intervals and Residuals

Removing the extra rows from the results table and adding the calculations of the confidenceintervals and the variance yields the following table (only the first two columns out of the fourare shown).

Note that the t value for 95% confidence intervals with 6 degrees if freedom is: t = 2.4469.

=C16^2Variance18

=C15*2.4469=B15*2.446995% conf. int.17

=LINEST(D2:D11,A2:C11,1,1)=LINEST(D2:D11,A2:C11,1,1)R2, SE (y)16

=LINEST(D2:D11,A2:C11,1,1)=LINEST(D2:D11,A2:C11,1,1)std.dev.s15

=LINEST(D2:D11,A2:C11,1,1)=LINEST(D2:D11,A2:C11,1,1)coeff.s14

a2a3 13

CBA

=D2-E2=$E$14+$D$14*A2+$C$14*B2+$B$14*C22

residuallogP(calc)1

FE

Page 46: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Polynomial RegressionPolynomial Regression

Options and InstructionsOptions and Instructions

The LINEST function and "Regression" tool from the "Analysis ToolPak" can be used forcarrying out linear regression. The LINEST function has the advantages over the "Regression"tool that the calculation results are automatically updated when the data is modified and theresults are easier to rearrange for documentation purposes. The "Regression" tool provides morestatistical data and the output is clearly labeled.

The use of the LINEST function for carrying out polynomial regression will be demonstratedhere in reference to Problem 2.3a in the book of Cutlip and Shacham. To prepare the data filearrange the columns of data so that the column of the dependent variable and the column of theindependent variable are next to each other and put the column of the independent variable asthe last one.

Copy these columns of the data from the POLYMATH data table and paste them into an Excelworksheet. Define additional columns that contain increasing powers of the independentvariable, up to the 5th degree.

Page 47: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Polynomial RegressionPolynomial Regression

Excel Formulas and Numerical ValuesExcel Formulas and Numerical Values

Numerical values

=B3^5=B3^4=B3^3=B3^210041.33

=B2^5=B2^4=B2^3=B2^25034.062

TK5TK4TK3TK2TKCp1

FEDCBA

2.356E+127.902E+092.650E+078.889E+04298.1573.67

7.594E+155.063E+123.375E+092.250E+061500205.8920

1.521E+125.568E+092.038E+077.462E+04273.1668.746

3.200E+111.600E+098.000E+064.000E+0420056.075

7.594E+105.063E+083.375E+062.250E+0415048.794

1.000E+101.000E+081.000E+061.000E+0410041.33

3.125E+086.250E+061.250E+052.500E+035034.062

TK5TK4TK3TK2TKCp1

FEDCBA

Page 48: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Polynomial RegressionPolynomial Regression

Using the LINEST Function for a 2Using the LINEST Function for a 2ndnd Degree Polynomial Degree Polynomial

To solve for a second order polynomial (with three parameters) mark an area of 3 rows and 3columns.

Type in LINEST(A2:A20, B2:C20, TRUE,TRUE) and press CONTROL+SHIFT+ENTERto enter this formula into all the marked cells.

Note that the range A2:A20 is the range where the dependent variable values are stored, therange B2:C20 is the range where the independent variable values are stored, the first logicalvariable TRUE (or the number 1) indicates that the parameter a0 cannot be assumed to be zeroand the second logical variable TRUE indicates that a matrix of regression statistics should alsobe returned.

The results obtained do not include any labeling and labeling is added manually.

Page 49: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Polynomial RegressionPolynomial Regression

Results for a 2Results for a 2ndnd Degree Polynomial Degree Polynomial

#N/A2.6106265970.998331R2, SE (y)26

1.609708680.0054367943.53E-06std.dev.s25

17.74273280.21778651-6.16E-05coeff.s24

a0a1a2 23

DCBA

=C26^2Variance28

=2.1199*C25=2.1199*B2595% conf. int.27

=LINEST(A2:A20,B2:C20,1,1)=LINEST(A2:A20,B2:C20,1,1)R2, SE (y)26

=LINEST(A2:A20,B2:C20,1,1)=LINEST(A2:A20,B2:C20,1,1)std.dev.s25

=LINEST(A2:A20,B2:C20,1,1)=LINEST(A2:A20,B2:C20,1,1)coeff.s24

a1a2 23

CBA

Calculation of the confidence intervals and the variance (only the first two columns out of thefour are shown).

Page 50: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Multiple Nonlinear RegressionMultiple Nonlinear Regression

InstructionsInstructions

To carry out multiple nonlinear regression an objective function containing the sum ofsquares of the errors is prepared and this objective function is be minimized by means ofthe "Solver" tool by changing the regression model parameters.

Demo 6c is used as an Example.

In this particular example the Antoine equation is fitted to vapor pressure (Vp) versustemperature (T °C) data. Thus, the objective function to be minimized is the following.

(5)

After copying the independent and dependent variable data from the POLYMATH file andpasting them into an Excel worksheet the objective function can be calculated in threesuccessive columns.

2

1

2

)(^10∑

=

++−=

N

j jj TC

BAVps

Page 51: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Multiple Nonlinear RegressionMultiple Nonlinear Regression

Excel FormulasExcel Formulas

In this table the initial estimates for the parameters A, B and C are also shown.

=D9^2=B9-C9=10^($B$1+$B$2/(A9+$B$3))5-19.69

=D8^2=B8-C8=10^($B$1+$B$2/(A8+$B$3))1-36.78

of Residuals(Pv)-(Pv)calc10^(A+B/(TC+C)) 7

Sum of Sqrs.Residual(Pv)calcPv (mmHg)TC6

5

=E18/(10-3)Variance4

273C3

-2035.33B2

8.752A1

EDCBA

Page 52: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Multiple Nonlinear RegressionMultiple Nonlinear Regression

Numerical Values at the Initial EstimateNumerical Values at the Initial Estimate

47701.1174Sum 1845102.0196-212.3724972.372476080.117

131.242211.456188.543910026.114…

110.046710.490349.50976015.41371.99968.485331.5147407.61210.34203.215916.784120-2.6110.48300.69509.305010-11.5100.0611-0.24715.24715-19.690.1415-0.37621.37621-36.78

of Residuals(Pv)-(Pv)calc10^(A+B/(TC+C)) 7Sum of SquaresResiduallog(Pv)calcPv (mmHg)TC6

5 6814.45Variance4EDCBA

Page 53: Instructions for Converting POLYMATH Solutions to Excel Worksheets

Multiple Nonlinear RegressionMultiple Nonlinear Regression

Numerical Values at the SolutionNumerical Values at the Solution

The sum of squares of errors is stored in cell C18. The "Solver" tool is used to minimizethis value while changing the values of the parameters A, B and C (in cells B1, B2 and B3).

2.2819Variance4

202.14C3

-1054.98B2

6.6185A1

BA