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

Question:

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:

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

Asked By: Joshua

||

Answers:

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]
Answered By: Oscar Benjamin
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.