title: apply condition to the optimized parameters using optim
body: <p>Suppose I want to optimise the a vector of parameters <code>x</code> using the function below</p>
  <pre><code>fr &lt;- function(x) {   
      x1 &lt;- x[1]
      x2 &lt;- x[2]
      x3 &lt;- x[2]
      x4 &lt;- x[2]
      100 * (x2 - x1 * x1)^2 + (1 - x1)^2 + x3 + x4
   }
  
  temp &lt;- optim(c(1, 1.5, 1.8, 1.9), fr)
  </code></pre>
  <p>The <code>x</code> being optimised cannot be sorted i.e. they have a natural order to them with first element of <code>x</code> being always the smallest and last element being always the largest. I want to retain these after optimisation as well.
  After the optimisation is done, the optimised parameters are as follows:</p>
  <pre><code>temp$par
  [1] 0.3334119 0.1011343 3.2182704 2.7068277
  </code></pre>
  <p>Is there anyway I can apply a condition to the optimised parameters such that they are in an ascending order i.e. following condition is satisfied</p>
  <pre><code>temp$par[1] &lt; temp$par[2] &lt; temp$par[3] &lt; temp$par[4]    
  </code></pre>