MATLAB: Array indexing multiple equations

differential equationsmultiple state variables

x1(i+1)=x1(i)+x2(i);
x3(i+1)=x3(i)+x4(i);
x5(i+1)=x5(i)+x6(i);
x2(i+1)=x2(i)+cos(x3(i))*x4(i+1)-x6(i+1);
x4(i+1)=x4(i);
x6(i+1)=x6(i)+cos(x5(i))*x2(i+1);
I came up with 6 equations for 6 variables. I have the equations above. x2(i+1) depends on x4(i+1) but that value is not calculated until x2(i+1) is calculated. How do I solve this problem do I need more equations?

Best Answer

You need to do some algebra on these equations before you solve them.
The variable x4 is a constant (x4(i+1) = x4(i) tells us this), so replace x4(i+1) -> x4(i) in the equation for x2(i+1) to give:
x2(i+1)=x2(i)+cos(x3(i))*x4(i)-x6(i+1); (*)
Now substitute x6(i+1)=x6(i)+cos(x5(i))*x2(i+1) into this equation (*) and solve for x2(i+1). This will give:
x2(i+1)=( x2(i)+cos(x3(i))*x4(i)-x6(i) )/( 1+cos(x5(i)) );
Finally, substitute x2(i+1)=( x2(i)+cos(x3(i))*x4(i)-x6(i) )/( 1+cos(x5(i)) ) into the equation for x6(i+1) to give
x6(i+1)=x6(i)+cos(x5(i))*( x2(i)+cos(x3(i))*x4(i)-x6(i) )/( 1+cos(x5(i)) );
Now you should be okay to solve this problem within a for-loop provided you have a known initial condition.