Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8477647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:31:31+00:00 2026-06-10T18:31:31+00:00

I am using sympy and numpy to solve the following the problem: Given a

  • 0

I am using sympy and numpy to solve the following the problem:

Given a point (x0, y0) and a curve y=a*x**2+b*x+c, compute the minimal distances of (x0, y0) to (x,y).

from sympy.core.symbol import symbols
from sympy.solvers.solvers import solve
from sympy.utilities.lambdify import lambdify

x, y = symbols('x y')    
a,b,c, x0, y0 = symbols('a b c x0 y0')
y = a*x**2 + b*x + c
dist2 = (x-x0)**2 + (y-y0)**2
sol = solve(dist2.diff(x), x)
dist2_diff_solve = lambdify( (x0,y0,a,b,c), solve(dist2.diff(x),x), modules='numpy')

Until now, every thing is fine. I can even get some results:

dist2_diff_solve(1, 1, 1, 1, 1)

[0.31718264650678707, (-0.9085913232533936-0.8665105933073626j),    
(-0.9085913232533936+0.8665105933073626j)]

However, with another group of parameters, I have problems:

dist2_diff_solve(664515.9375, 3998106.0, 0.053674994761459802, -71340.561832823907,    23709057427.266102)

*** ValueError: negative number cannot be raised to a fractional power

I think this is a bug from lambdify, as I can do the following:

sol[0].evalf(subs={x0:664515.9375, y0:3998106.0, a:0.053674994761459802, b:-71340.561832823907, c:23709057427.266102})
664515.759983973 + .0e-19*I

I need lambdify because I need to compute a large number (~100K) of computation (vectorize) at one time. Can any one confirm this is a bug from lambdify? Any comments / suggestions are welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:31:33+00:00Added an answer on June 10, 2026 at 6:31 pm

    I found one related question: negative pow in python

    and solved this problem simply by adding +0j to a, that is:

    dist2_diff_solve(664515.9375+0j, 3998106.0, 0.053674994761459802, -71340.561832823907, 23709057427.266102)
    
    [(664515.7418921513+3.552713678800501e-15j), (664600.9266076663+5.329070518200751e-15j), (664564.8069210749-1.4210854715202004e-14j)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using mercurial, I've run into an odd problem where a line from one committer
I was wondering how to create a matrix and compute its inverse using SymPy
how to simplify exponents in equations in sympy from sympy import symbols a,b,c,d,e,f=symbols('abcdef') j=(a**b**5)**(b**10)
I am using the wonderful sympy in python to generate the augmented system of
Using Java,I have to fetch multiple sets of values from an XML file to
Using Yii, I want to delete all the rows that are not from today.
I'm trying to use an equation that I've generated using sympy.Eq(func, var) in a
I want to integrate exp(-(x^2 + y^2)) in python using sympy library. I could
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
I am currently using Sympy to help me perform mathematical calculations. Right now, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.