I’m getting an index error in my function and this is showing that “too many indices for an array”.
I’m fighting this issue for more than the last 3-4 days and can’t find any solution by myself.
Please help

The error message implies that your Z and dZ are not the same size.

It’s strange. I did not see any error in your apparent code. I guess you are making a mistake somewhere else. Please check the M from me for further instructions.