# [Maxima] Can Maxima solve this optimization problem?

Paul Smith phhs80 at gmail.com
Tue Jan 8 06:38:17 CST 2008

```Thanks, Andrej, for your clever solution. But suppose now that instead of

integral of x(t) with t from 0 to 1,

you have the following objective function:

integral of sin( x(t) ) with t from 0 to 1.

Is Maxima still able to solve the maximization problem?

Paul

On Jan 7, 2008 5:32 PM, Andrej Vodopivec <andrej.vodopivec at gmail.com> wrote:
> You can try like this:
>
> You are maximizing the area under u(t) from 0 to 1 under two
> conditions: u(0)=u(1)=0 and |du/dt|<=1. Take discrete set of points
> x[1]=0, ..., x[N]=1 such that x[i+1]=x[i]+h, where h=1/(N-1). Let
> u[i]=u(x[i]). Approximate the derivative du/dt at x[i] with
> (u[i+1]-u[i])/h.  The conditions on the derivatives are now -h <
> u[i+1]-u[i] < h. The area under the curve is approximated with
> area=sum((u[i]+u[i+1])*h/2, i, 1, N-1). Along with the conditions
> u[0]=u[N]=0 this is a linear program. You can solve it as shown below
> (with N=51):
>
> (%i3) N : 51\$
>       h : 1.0/(N-1)\$
>       vals : makelist(concat(u, i), i, 1, N)\$
>       ineq : append(
>               makelist(vals[i+1]-vals[i] <  h, i, 1, N-1),
>               makelist(vals[i+1]-vals[i] > -h, i, 1, N-1))\$
>       eq : [vals[1]=0, vals[N]=0]\$
>       conditions : append(ineq, eq)\$
>       area : sum((vals[i]+vals[i+1])*h/2, i, 1, N-1)\$
> (%i10) [ar, va] : maximize_lp(area, conditions)\$
> (%i11) data : makelist([(i-1)*h, assoc(vals[i], va)], i, 1, N)\$
> (%i12) draw2d(points_joined = true, point_size=0, points(data));
>
> HTH
>
> Andrej
>
>
> On Jan 7, 2008 1:33 AM, Paul Smith <phhs80 at gmail.com> wrote:
> > Dear All,
> >
> > I am trying to solve the following maximization problem with Maxima:
> >
> > find x(t) (continuous) that maximizes the
> >
> > integral of x(t) with t from 0 to 1,
> >
> > subject to the constraints
> >
> > dx/dt = u,
> >
> > |u| <= 1,
> >
> > x(0) = x(1) = 0.
> >
> > The analytical solution can be obtained easily, but I am trying to
> > understand whether Maxima is able to solve numerically problems like
> > this one. I have tried to find an approximate solution through
> > discretization of the objective function but with no success so far.
> >