Th order implementation of Runge Kutta in AMPL language

Hi

i want to use 4th order implementation of Runge Kutta in AMPL language . where the second order is given

s.t. lambda_x {i in 0…n-1} : x[i+1] = x[i] + 0.5h( fx[i]+fx[i+1]) ;

Kind Regards,
Emad

1 Like

Can you explain what h is? The expression h(fx[i]+fx[i+1]) suggests that h is some kind of function, but AMPL doesn’t know about any functions having that name.

Hi,

@4er I think h parameter is the step in Runge Kutta’s method.

@Emad_Abdullah how are you planning to implement Runge Kutta with AMPL? I guess you want AMPL to fix the values for every iteration (n steps), and you are using the x’s, fx’s and perhaps some y’s as variables, but which function are you going to minimize? Could you tell us more about your model?

sorry
“h” is actually is step size
and the equation should be like the following
s.t. lambda_x {i in 0…n-1} : x[i+1] = x[i] + 0.5 * h * ( fx[i]+fx[i+1]) ;

I solving an optimal control problem using IPOPT
and the x equation is like the following
var fx {i in 0…N} = -lambda * x[i] + w * (x2[i]-myu) * H[i] ;
where the second order is given
s.t. lambda_x {i in 0…n-1} : x[i+1] = x[i] + 0.5h( fx[i]+fx[i+1]) ;

You can write these AMPL statements:

param h;
var x {i in 1..N};
var fx {i in 0..N} = -lambda*x[i] + w*(x2[i]-myu)*H[i] ;
s.t. lambda_x {i in 0..n-1}: x[i+1] = x[i] + 0.5*h*( fx[i]+fx[i+1]) ;

However, to make this work in AMPL, you first have to define lambda, w, x2, myu, and H. Which of these are variables (to be optimized by the solver) and which are parameters (given as data)?

As @marcos has mentioned, if this is to be an optimal control problem, then you will also need to give an expression for the objective function in a minimize or maximize statement.

1 Like