Solving a system of equations using mpmath.findroot

asked 2016-02-27 08:55:33 +0100

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Hi All,

A few weeks ago, the code below, which was designed to compute some points was working perfectly. After compiling it a few days ago, I got : ValueError: Could not find root within given tolerance. (7235.55 > 2.1684e-19) Try another starting point or tweak arguments.

Please I will be very pleased if someone could help me solve this problem. Thanks for your understanding

 import mpmath
 theta=pi/12

p1=vector([0,0,0])
p2=vector([-12,0,0])
p3=vector([1/24,-17/24*sqrt(287),0])

#Calcul du point p4

x4,r4=var('x4,r4')
T4=solve([(p1[0]-x4)^2+(p1[1]-r4*cos(theta))^2+(p1[2]-r4*sin(theta))^2==25,(p2[0]-x4)^2+(p2[1]-r4*cos(theta))^2+(p2[2]-r4*sin(theta))^2==100],x4,r4,solution_dict=True)

a=T4[0].values()
b=T4[1].values()
p4=vector([a[1],0,0])
if b[0]<0:
    p4[1]=a[0]*cos(theta)
    p4[2]=a[0]*sin(theta)
else:
    p4[1]=b[0]*cos(theta)
    p4[2]=b[0]*sin(theta)


var(" x5 y5 z5 x6 y6 z6 x7 y7 z7")

eq25 = (p2[0]-x5)^2+(p2[1]-y5)^2+(p2[2]-z5)^2-100 == 0
eq46 = (p4[0]-x6)^2+(p4[1]-y6)^2+(p4[2]-z6)^2-144 == 0
eq45 = (p4[0]-x5)^2+(p4[1]-y5)^2+(p4[2]-z5)^2-121 == 0
eq16 = (p1[0]-x6)^2+(p1[1]-y6)^2+(p1[2]-z6)^2-100 == 0
eq27 = (p2[0]-x7)^2+(p2[1]-y7)^2+(p2[2]-z7)^2-144 == 0
eq37 = (p3[0]-x7)^2+(p3[1]-y7)^2+(p3[2]-z7)^2-144 == 0
eq56 = (x6-x5)^2+(y6-y5)^2+(z6-z5)^2-144 == 0
eq67 = (x6-x7)^2+(y6-y7)^2+(z6-z7)^2-100 == 0
eq57 = (x7-x5)^2+(y7-y5)^2+(z7-z5)^2-25 == 0

# Calcul des points p5, p6, et p7

f= [lambda x5,y5,z5,x6,y6,z6,x7,y7,z7: eq25.lhs().subs(x5=RR(x5), y5=RR(y5), z5=RR(z5), x6=RR(x6), y6=RR(y6), z6=RR(z6), x7=RR(x7), y7=RR(y7), z7=RR(z7)),
    lambda x5,y5,z5,x6,y6,z6,x7,y7,z7: eq46.lhs().subs(x5=RR(x5), y5=RR(y5), z5=RR(z5), x6=RR(x6), y6=RR(y6), z6=RR(z6), x7=RR(x7), y7=RR(y7), z7=RR(z7)),
    lambda x5,y5,z5,x6,y6,z6,x7,y7,z7: eq45.lhs().subs(x5=RR(x5), y5=RR(y5), z5=RR(z5), x6=RR(x6), y6=RR(y6), z6=RR(z6), x7=RR(x7), y7=RR(y7), z7=RR(z7)),
    lambda x5,y5,z5,x6,y6,z6,x7,y7,z7: eq16.lhs().subs(x5=RR(x5), y5=RR(y5), z5=RR(z5), x6=RR(x6), y6=RR(y6), z6=RR(z6), x7=RR(x7), y7=RR(y7), z7=RR(z7)),
    lambda x5,y5,z5,x6,y6,z6,x7,y7,z7: eq27.lhs().subs(x5=RR(x5), y5=RR(y5), z5=RR(z5), x6=RR(x6), y6=RR(y6), z6=RR(z6), x7=RR ...
(more)
edit retag flag offensive close merge delete

Comments

Can you edit your post using the following tips? 1. To display code blocks properly, select them and click the "code formatting" button (the one with "101 010"). 2. If possible, say which version of Sage you are using. 3. Did you change the version of Sage between the time the code was working and now? 4. In general, don't tick the "community wiki" checkbox.

slelievre gravatar imageslelievre ( 2016-02-27 13:50:10 +0100 )edit