The rank condition is not verified

Hello, I’m working on an OLG model with dynare and get the message that the rank condition is not verified.
I worked on that for days but didn’t fix it, could anyone help on this ?
The codes are attached.

This is hard to tell. Could it be related to [Timing of capital in two sector economy)

Dear Jpfeifer,

Thanks very much for your advice, I tried another form of the model.
At this time, the rank problem is fixed, but it report that “Simulation terminated with NaN or Inf in the residuals or endogenous variables. There is most likely something wrong with your model”.

Could you help me to have a look at this?
The code is attached, thanks in advance.