title: Differential equations/optimal control in AMPL
body: <p>Does someone has an experience in solving differential equations in AMPL? I googled a lot, but no suitable results...</p>
  
  <p>In google groups I've found a simple "hand-made" example, but it doesn't work...</p>
  
  <p>So, this example I found.</p>
  
  <p>Consider this ODE: </p>
  
  <pre><code>   x' = -ax + u, x(0) = 0. 
  </code></pre>
  
  <p>where a=0.2 is a parameter; x = state variable, between 0 and 9; u = 
  input variable, between 0 and 5. You can write this in AMPL as follows 
  (using textbook forward Euler): </p>
  
  <pre><code>param N := 10; # no. of integration steps 
  param dt := 0.01; # integration step size 
  param a := 0.2; 
  set kset ordered := 0..N; 
  var x{kset}, &gt;= 0, &lt;= 9; 
  var u{kset}, &gt;= 0, &lt;= 5; 
  minimize obj: 0; 
  subject to 
  c1{k in 1..N}: (x[k] - x[k-1])/dt = -a*x[k-1] + u[k-1]; 
  option solver ipopt; 
  solve; 
  display x, u;
  </code></pre>
  
  <p>The solution gives me zeros for u and x... It is no wonder because of this line </p>
  
  <blockquote>
    <p>minimize obj: 0;</p>
  </blockquote>
  
  <p>As far as I understood we need to represent the problem as a system of algebraic equations, but what will be a goal function in this case???</p>
  
  <p>So, can somebody give any suggestions or proper examples?</p>
  
  <p>Thanks in advance.</p>