Main
~~* [[http://apmonitor.com/online/view_pass.php?f=twobar_v1.apm | Solve Initial Version]]~~

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v2.apm | Solve with SQRT removed]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v3.apm | Solve with added constraints and no SQRT]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v4.apm | Solve with added constraints and explicit definition of some variables]]

----

The following models are taken from the homework assignment on the [[Main/TwoBarTruss | Two Bar Truss problem]]. The initial version is most similar to how the problem would be posed in a textbook. Removing the SQRT and adding constraints to the variables shows improvements in model convergence. Explicit definition of some of the variables adds additional improvements.

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v1.apm | Solve Initial Version]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v2.apm | Solve with SQRT removed]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v3.apm | Solve with added constraints and no SQRT]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v4.apm | Solve with added constraints and explicit definition of some variables]]

## Best Practices for Open-Equation Modeling

## Main.EquationResiduals History

Hide minor edits - Show changes to output

Changed line 36 from:

!!!! Exercise ~~3 Results~~

to:

!!!! Exercise Results for the Two Bar Truss

Deleted lines 10-14:

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v2.apm | Solve with SQRT removed]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v3.apm | Solve with added constraints and no SQRT]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v4.apm | Solve with added constraints and explicit definition of some variables]]

Added lines 13-14:

!!!! Tips for Improved Convergence

Added lines 33-41:

----

The following models are taken from the homework assignment on the [[Main/TwoBarTruss | Two Bar Truss problem]]. The initial version is most similar to how the problem would be posed in a textbook. Removing the SQRT and adding constraints to the variables shows improvements in model convergence. Explicit definition of some of the variables adds additional improvements.

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v1.apm | Solve Initial Version]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v2.apm | Solve with SQRT removed]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v3.apm | Solve with added constraints and no SQRT]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v4.apm | Solve with added constraints and explicit definition of some variables]]

Added lines 1-52:

(:title Best Practices for Open-Equation Modeling:)

(:keywords mathematical modeling, nonlinear, optimization, engineering optimization, interior point, active set, differential, algebraic, modeling language, university course:)

(:description Mathematical modeling is necessary to apply optimization techniques in engineering. Improved structure of the models leads to faster and more robust convergence.:)

!!!! Modeling Exercise

Modeling often constitutes most of the effort on an optimization project. There is some art in the way a programmer poses the model in a way that allows solvers to efficiently find a solution. Below are some tips and an exercise on ways to rearrange the model equations for improved convergence.

[[Attach:twobar_rearrangement.pdf | Worksheet with Modeling Exercises]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v1.apm | Solve Initial Version]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v2.apm | Solve with SQRT removed]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v3.apm | Solve with added constraints and no SQRT]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v4.apm | Solve with added constraints and explicit definition of some variables]]

# Rearrange to equation in residual form to:

## Avoid divide by zero

## Minimize use of functions like sqrt, log, exp, etc.

## Have continuous first and second derivatives

## Fit the equation into a linear or quadratic form

# Bounds

## Include variable bounds to exclude infeasible solutions

## Variable bounds to avoid regions of strong nonlinearity

## Caution: watch for infeasible solutions

# Scaling:

## Scale absolute value of variables to 1e-3 to 1e3

## Scale absolute value of equation residuals to 1e-3 to 1e3

## Better that 1st derivative values are closer to 1.0

# Good initial conditions:

## Starting near a solution can improve convergence

## Try multiple initial conditions to verify global solution (non-convex problems)

## Explicitly calculate intermediate values

# Check iteration summary for improved convergence

----

(:html:)

<div id="disqus_thread"></div>

<script type="text/javascript">

/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */

var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname

/* * * DON'T EDIT BELOW THIS LINE * * */

(function() {

var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;

dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';

(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);

})();

</script>

<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>

<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

(:htmlend:)

(:keywords mathematical modeling, nonlinear, optimization, engineering optimization, interior point, active set, differential, algebraic, modeling language, university course:)

(:description Mathematical modeling is necessary to apply optimization techniques in engineering. Improved structure of the models leads to faster and more robust convergence.:)

!!!! Modeling Exercise

Modeling often constitutes most of the effort on an optimization project. There is some art in the way a programmer poses the model in a way that allows solvers to efficiently find a solution. Below are some tips and an exercise on ways to rearrange the model equations for improved convergence.

[[Attach:twobar_rearrangement.pdf | Worksheet with Modeling Exercises]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v1.apm | Solve Initial Version]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v2.apm | Solve with SQRT removed]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v3.apm | Solve with added constraints and no SQRT]]

* [[http://apmonitor.com/online/view_pass.php?f=twobar_v4.apm | Solve with added constraints and explicit definition of some variables]]

# Rearrange to equation in residual form to:

## Avoid divide by zero

## Minimize use of functions like sqrt, log, exp, etc.

## Have continuous first and second derivatives

## Fit the equation into a linear or quadratic form

# Bounds

## Include variable bounds to exclude infeasible solutions

## Variable bounds to avoid regions of strong nonlinearity

## Caution: watch for infeasible solutions

# Scaling:

## Scale absolute value of variables to 1e-3 to 1e3

## Scale absolute value of equation residuals to 1e-3 to 1e3

## Better that 1st derivative values are closer to 1.0

# Good initial conditions:

## Starting near a solution can improve convergence

## Try multiple initial conditions to verify global solution (non-convex problems)

## Explicitly calculate intermediate values

# Check iteration summary for improved convergence

----

(:html:)

<div id="disqus_thread"></div>

<script type="text/javascript">

/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */

var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname

/* * * DON'T EDIT BELOW THIS LINE * * */

(function() {

var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;

dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';

(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);

})();

</script>

<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>

<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

(:htmlend:)