Bryson-Denham Problem

Apps.BrysonDenhamProblem History

Show minor edits - Show changes to markup

March 27, 2023, at 05:41 PM by 10.35.117.248 -
Added line 101:
Added line 73:

m.options.SOLVER = 2

July 05, 2020, at 03:10 AM by 12.217.227.229 -
Added lines 7-10:

(:html:) <iframe width="560" height="315" src="https://www.youtube.com/embed/OL4yu4yoHC0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> (:htmlend:)

Deleted lines 27-30:

(:html:) <iframe width="560" height="315" src="https://www.youtube.com/embed/OL4yu4yoHC0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> (:htmlend:)

July 05, 2020, at 03:09 AM by 173.166.196.185 -
Added lines 24-27:

(:html:) <iframe width="560" height="315" src="https://www.youtube.com/embed/OL4yu4yoHC0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> (:htmlend:)

July 05, 2020, at 01:33 AM by 173.166.196.185 -
Changed line 34 from:

m = GEKKO()

to:

m = GEKKO(remote=False)

Changed lines 50-52 from:

m.Minimize(final*1e5*x**2) m.Minimize(final*1e5*(v+1)**2)

to:

soft = True if soft:

    # soft terminal constraint
    m.Minimize(final*1e5*x**2)
    m.Minimize(final*1e5*(v+1)**2)

else:

    # hard terminal constraint
    xf = m.Param();    vf = m.Param()
    m.free(xf);        m.free(vf)
    m.fix_final(xf,0); m.fix_final(vf,-1)
    # connect endpoint parameters to x and v
    m.Equations([xf==x,vf==v])
Changed lines 71-72 from:

plt.figure(figsize=(10,6))

to:
  1. Create a figure

plt.figure(figsize=(10,4))

June 21, 2020, at 01:56 PM by 136.36.211.159 -
Changed line 40 from:

u = m.Var(value=-6,lb=-6)

to:

u = m.Var(value=-6)

June 21, 2020, at 01:55 PM by 136.36.211.159 -
Added lines 27-28:
Deleted lines 84-86:
June 21, 2020, at 01:54 PM by 136.36.211.159 -
Changed lines 27-32 from:

(:html:) <!-- <iframe width="560" height="315" src="https://www.youtube.com/embed/pgJ0jbfFBUE" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

to:

(:source lang=python:) import numpy as np import matplotlib.pyplot as plt from gekko import GEKKO

m = GEKKO() nt = 101; m.time = np.linspace(0,1,nt)

  1. Variables

x = m.Var(value=0,ub=1/9) v = m.Var(value=1) u = m.Var(value=-6,lb=-6)

p = np.zeros(nt); p[-1] = 1.0 final = m.Param(value=p)

  1. Equations

m.Equation(x.dt()==v) m.Equation(v.dt()==u)

  1. Final conditions

m.Minimize(final*1e5*x**2) m.Minimize(final*1e5*(v+1)**2)

  1. Objective Function

obj = m.Intermediate(0.5*m.integral(u**2)) m.Minimize(final*obj)

m.options.IMODE = 6 m.options.NODES = 2 m.solve()

plt.figure(figsize=(10,6)) plt.subplot(2,2,1) plt.plot([0,1],[1/9,1/9],'r:',label=r'$x<\frac{1}{9}$') plt.plot(m.time,x.value,'k-',lw=2,label=r'$x$') plt.ylabel('Position') plt.legend(loc='best') plt.subplot(2,2,2) plt.plot(m.time,v.value,'b--',lw=2,label=r'$v$') plt.ylabel('Velocity') plt.legend(loc='best') plt.subplot(2,2,3) plt.plot(m.time,u.value,'r--',lw=2,label=r'$u$') plt.ylabel('Thrust') plt.legend(loc='best') plt.xlabel('Time') plt.subplot(2,2,4) plt.plot(m.time,obj.value,'g-',lw=2,label=r'$\frac{1}{2} \int u^2$') plt.text(0.5,3.0,'Final Value = '+str(np.round(obj.value[-1],2))) plt.ylabel('Objective') plt.legend(loc='best') plt.xlabel('Time') plt.show() (:sourceend:)

Changed line 85 from:
to:
June 21, 2020, at 05:04 AM by 136.36.211.159 -
Deleted lines 35-54:

(: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 = 'https://' + 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="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    <a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

(:htmlend:)

Changed line 9 from:

The parameter u is the acceleration can be adjusted over the time horizon from a starting time of zero to a final time of one. The variable x is the position and v is the velocity.

to:

The parameter u (acceleration) is adjusted over the time horizon from a starting time of zero to a final time of one. The variable x is the position and v is the velocity.

Added lines 24-36:

Solution

(:html:) <!-- <iframe width="560" height="315" src="https://www.youtube.com/embed/pgJ0jbfFBUE" frameborder="0" allowfullscreen></iframe>

(:htmlend:)

Changed line 9 from:

The parameter u is the acceleration can be adjusted over the time horizon from a starting time of zero to a time of one. The variable x is the position and v is the velocity.

to:

The parameter u is the acceleration can be adjusted over the time horizon from a starting time of zero to a final time of one. The variable x is the position and v is the velocity.

Changed lines 15-23 from:

$$\quad \frac{dx(t)}{dt} = v $$

$$\quad \frac{dv(t)}{dt} = u$$

$$\quad x(0) \; = \; x(1) \; = \; 0$$

$$\quad v(0) \; = \; -v(1) \; = \; 1$$

$$\quad x(t) \le \ell, \ell=\frac{1}{9}$$

to:

$$\frac{dx(t)}{dt} = v(t) $$

$$\frac{dv(t)}{dt} = u(t) $$

$$x(0) \; = \; x(1) \; = \; 0$$

$$v(0) \; = \; -v(1) \; = \; 1$$

$$x(t) \le \ell, \; \ell=\frac{1}{9}$$

Added lines 1-42:

(:title Bryson-Denham Problem:) (:keywords Benchmark, Python, nonlinear control, dynamic programming, optimal control:) (:description Minimize the integral of the control input while meeting certain path and final time constraints.:)

The Bryson-Denham optimal control problem is a benchmark test problem for optimal control algorithms.

Problem Statement

The parameter u is the acceleration can be adjusted over the time horizon from a starting time of zero to a time of one. The variable x is the position and v is the velocity.

$$\min J = \frac{1}{2} \; \int_0^1 u^2(t) dt$$

$$\mathrm{subject\;to}$$

$$\quad \frac{dx(t)}{dt} = v $$

$$\quad \frac{dv(t)}{dt} = u$$

$$\quad x(0) \; = \; x(1) \; = \; 0$$

$$\quad v(0) \; = \; -v(1) \; = \; 1$$

$$\quad x(t) \le \ell, \ell=\frac{1}{9}$$


(: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 = 'https://' + 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="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    <a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

(:htmlend:)