Seems to me you are simply solving a system of linear equations here. You can use JuMP for that.
JuMP