Hi Kukhokuhle,
The error you’re encountering with lsqnonlin might be because there is a mismatch in the size of the arrays being subtracted in the compute_error function. Specifically, the armCoords array and the qsim array do not have the same number of elements when you attempt to compute the error by subtracting one from the other.
Here are a few ways you can try to resolve the issue:
- Check Array Sizes: Ensure that the armCoords and qsim arrays have the same number of elements before performing the subtraction. You can add debugging statements to print their sizes just before the subtraction operation.
- Consistent Output: The function you pass to lsqnonlin must return an array with a consistent number of elements.
- Simulation Output: Verify that the simulation output out contains the expected data with the correct dimensions.
- Finite Differences: The error in finitedifferences and computeFinDiffGradAndJac indicates that the Jacobian estimation step in lsqnonlin is failing due to inconsistent array sizes.Make sure that the function is vectorized properly and that it returns a vector of residuals.
Hope this helps.