Please reduce your code by removing everything not needed to reproduce the error. This includes plotting etc.
Note that you should try to remove a variable and see if the error is still there, and keep removing variables and reducing complexity of the code until it is a smaller example, such as: