Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sympy not finding a solution to equation, would numpy work?

I’m trying to build a system for simulating sliding done arbitrary slopes, but it requires that I find the intersection of half a circle and an arbitrary function. However, when I use sympy, it does find a solution despite one clearly existing.

Is there a numerical approach I could take to this in NumPy?

See code below, where x, y, and r and all constants:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

z = symbols('z')
print(solve(z * 1, ((r**2 - (z - x)**2) ** 0.5) + y))
p1 = plot(z, show=False)
p2 = plot(((r**2 - (z - x)**2) ** 0.5) + y, show=False)
p1.append(p2[0])
p1.show()

This results in:

[]

Despite a solution clearly existing:

enter image description here

Note that in the case used for testing, x=0.4, y=0.4, r=1

>Solution :

You are passing two arguments to solve but it should be a single argument as an equation (Eq):

In [58]: eq = Eq(z * 1, ((r**2 - (z - x)**2) ** 0.5) + y)

In [59]: eq
Out[59]: 
                    0.5      
    ⎛             2⎞         
z = ⎝1 - (z - 0.4) ⎠    + 0.4

In [60]: solve(eq)
Out[60]: [1.10710678118655]

A second argument, if provided, should be the symbol to solve for or a list of symbols to solve for e.g.:

In [61]: solve(eq, z)
Out[61]: [1.10710678118655]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading