Since you haven't solved any problem when you run this line A = sin(value(angle{j-1}) + value(u{j-1})), A will be Nan (as angle and u does not have any value yet)
You are simply setting up a nonlinear model, in a weird flawed way. It is not clear what you actually want to do. Do you want to use an A matrix which is based on the values computed in the last solve (previous k)? If you add assign([u{:}],.3) before the simulation loop, an initial value will be available., and when you solve the problem the second time, the new angle trajectory will be used. With that, you can remove your if-statement. Or perhaps you simply meant the if-switch to be based on k, not j.
Also, you want
constraint = [constraint, x{j+1} == x{j} + A*(u{j} - u{j-1});
angle{j+1} == angle{j} + (u{j} - u{j-1})];