# Bryson-Denham Problem (Detailed)

## Contents

## Problem description

A detailed version of the Bryson-Denham problem

```
% Copyright (c) 2007-2008 by Tomlab Optimization Inc.
```

## Define the independent variable, and phase:

It is common for the independent variable to be named "t", but any legal tomSym name is possible. The length of the time-interval is variable, so another tomSym symbol is created for that.

toms t tf p = tomPhase('p', t, 0, tf, 30); setPhase(p);

## A few constants.

% The name on the mathematics: options = struct; options.name = 'Bryson Denham Detailed'; x1max = 1/9; tfmax = 50;

## Define a list of states

After a phase has been defined, states can be created Note that the states can be given meaningful names, even though they are simply named x1...x3 in this particular problem.

tomStates x1 x2 x3 % Initial guess % The guess for tf must appear first in the list x0 = {tf == 0.5 icollocate({ x1 == 0 x2 == 1-2*t/tf x3 == 0 })}; cbox = {0 <= tf <= 50 -10 <= icollocate(x1) <= 10 -10 <= icollocate(x2) <= 10 -10 <= icollocate(x3) <= 10};

## Adding the control variable and equations

```
tomControls u
x0 = {x0
collocate(u == 0)};
cbox = {cbox
-5000 <= collocate(u) <= 5000};
```

## Equations

The equations are on a nonlinear DAE form, i.e. the states and their derivatives can be combined into arbitrary equations. Equations can also be specified point-wise, or using integrals. Integrals can be achieved by using the function integral(). Each equation must contain one or more equals (==) signs, or one or more greater than (>=) signs, or one or more less than (<=) signs.

usquared = u^2; ceq = collocate({ dot(x1) == x2 dot(x2) == u dot(x3) == 0.5*usquared 0 <= x1 <= x1max % Path constraint }); cbnd = {initial({ x1 == 0; x2 == 1; x3 == 0}) final({x1 == 0; x2 == -1})}; % The "objective" function to minimize. Cost can be specified at a point, % or integrated over time by using the function integral. % If costs are defined as many parts they should be added together. objective = final(x3);

## Build the .m files and general TOMLAB problem

Prob = sym2prob('con',objective,{cbox, ceq, cbnd},x0,options); % Solve the problem using any TOMLAB solver Result = tomRun('snopt', Prob, 1);

===== * * * =================================================================== * * * TOMLAB - Tomlab Optimization Inc. Development license 999001. Valid to 2010-02-05 ===================================================================================== Problem: --- 1: Bryson Denham Detailed f_k 3.998132387937474600 sum(|constr|) 0.000000810450297667 f(x_k) + sum(|constr|) 3.998133198387772100 f(x_0) 0.000000000000000000 Solver: snopt. EXIT=0. INFORM=1. SNOPT 7.2-5 NLP code Optimality conditions satisfied FuncEv 35 GradEv 33 ConstrEv 33 ConJacEv 33 Iter 32 MinorIter 177 CPU time: 0.218750 sec. Elapsed time: 0.171000 sec.