Re: [R] Can R solve this optimization problem?

From: Duncan Murdoch <>
Date: Sun, 06 Jan 2008 20:04:06 -0500

On 06/01/2008 7:55 PM, Paul Smith wrote:

> On Jan 7, 2008 12:18 AM, Duncan Murdoch <> wrote:

>>> I am trying to solve the following maximization problem with R:
>>> 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 R 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.
>> R doesn't provide any way to do this directly. If you really wanted to
>> do it in R, you'd need to choose some finite dimensional parametrization
>> of u (e.g. as a polynomial or spline, but the constraint on it would
>> make the choice tricky: maybe a linear spline?), then either evaluate
>> the integral analytically or numerically to give your objective
>> function. Then there are some optimizers available, but in my
>> experience they aren't very good on high dimensional problems: so your
>> solution would likely be quite crude.
>> I'd guess you'd be better off in Matlab, Octave, Maple or Mathematica
>> with a problem like this.
> Thanks, Duncan. I have placed a similar post in the Maxima list and
> another one in the Octave list. (I have never used splines; so I did
> not quite understand the method that you suggested to me.)

Linear splines are just piecewise linear functions. An easy way to parametrize them is by their value at a sequence of locations; they interpolate linearly between there.

x would be piecewise quadratic, so its integral would be a sum of cubic terms.

Duncan Murdoch mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon 07 Jan 2008 - 01:08:12 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 07 Jan 2008 - 02:30:05 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive