Simplest way to solve mathematical equations in Python

后端 未结 15 1719
自闭症患者
自闭症患者 2020-12-13 10:15

I want to solve a set of equations, linear, or sometimes quadratic. I don\'t have a specific problem, but often, I have been in this situation often.

It is simple to

15条回答
  •  暖寄归人
    2020-12-13 10:42

    Here is how to solve your original question using Python (via Sage). This basically clarifies the remark Paul McMillan makes above.

    sage: a,b,c = var('a,b,c')
    sage: solve([a+b+c==1000, a^2+b^2==c^2], a,b,c)
    [[a == 1000*(r1 + sqrt(r1^2 + 2000*r1 - 1000000))/(r1 + sqrt(r1^2 + 2000*r1 - 1000000) + 1000), b == -1/2*r1 - 1/2*sqrt(r1^2 + 2000*r1 - 1000000) + 500, c == r1], [a == 1000*(r2 - sqrt(r2^2 + 2000*r2 - 1000000))/(r2 - sqrt(r2^2 + 2000*r2 - 1000000) + 1000), b == -1/2*r2 + 1/2*sqrt(r2^2 + 2000*r2 - 1000000) + 500, c == r2]]
    

提交回复
热议问题