merge from raoulb-pr2198_review_1
Avoid 'solve' call and replace asserts

- use direct solution of linear equations rather than call to 'solve'
- improved if...raise ValueError instead of assert
- minor style changes and cleanup