# Solving Dynamical Optimization Problems in Excel

You can combine ExceLab calculus functions with either native Excel Solver or NLSOLVE to solve a variety of parameter estimation and dynamical optimization problems.

If you have learned how to obtain a solution with the calculus functions, you are almost done! Setting up a parameter or dynamical optimization problem is straightforward with just a couple more steps:

1. Solve your model as you would normally do using the relevant calculus solvers. Make sure to use variables with initial reasonable values for the model parameters you want to optimize instead of just hardcoding their values into your model formulas.

Your design parameters can be any parameters that influence the system behavior including coefficients, bcs, initial values, etc.

2. The next step is to define constraint formulas to penalize the deviation of your initial solution from your target value. NLSOLVE interprets equality constraints in relation to zero and inequality constraints in relation to greater than or equal to zero. Typically you specify a constraint formula in the following form:

= Initial solution value – Target Value

• If your initial solution is a single value (e.g., an integral evaluation) you can reference it directly in your constraint formulas.
• On the other hand, if your initial solution is an array result (e.g., ODE or PDE solution), you can still define arbitrary formula constraints on a single or a range of values in the result array. The only requirement is that when referencing any value or range of values in the initial solution result in your constraint formulas you must do so using the auxiliary function DYNVAL. DYNVAL is a dummy function that simply returns the value of its argument but in this context, it ensures that its argument is dynamically evaluated during the optimization.

3. The final step is to solve for the optimal model parameters that will satisfy your constraints formula (i.e., drive their values to zero). You have two choices:

• If you do not have a cost formula to maximize or minimize, use NLSOLVE to solve the system of constraints formulas for the unknown model parameters.
• On the other hand, if you do have a cost formula, then use Excel Solver to setup an optimization problem to minimize or maximize your cost formula subject to the constraint formulas you have defined.

### The best way to learn is by viewing the examples.

Question or Comment? Email us:
support @ excel-works.com ExceLab: Transforming Excel into a Calculus Power House

ExceLab functions and methods are protected by USA Patents 10628634, 10114812, 9892108 and 9286286.