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

  • Home
  • SEARCH
  • 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 8270265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:31:49+00:00 2026-06-08T06:31:49+00:00

I am currently using Sympy to help me perform mathematical calculations. Right now, I

  • 0

I am currently using Sympy to help me perform mathematical calculations. Right now, I am trying to perform a numerical integration, but keep getting an error any time I run the script. Here is the script:

from sympy import *
cst = { 'qe':1.60217646*10**-19, 'm0':N(1.25663706*10**-6) }

d = 3.6*10**-2
l = 20.3*10**-2
n = 217.0
I = 10.2

# Circum of loops
circ = l/n;
# Radius
r = N( circ/(2*pi) )
# Flux through a ring a distance R from the ceter
def flux(rad, I, loopRad):
    distFromWire = loopRad - rad
    bPoint = cst['m0']*I/(2*pi*distFromWire)
    return ( bPoint*2*pi*rad )

# Integrate from r=0 to r=wireRad
x = Symbol('x')
ig = Symbol('ig')
ig = flux(x, I, r)
print(ig)
integrate(ig*x,x)

I am sure there is probably something wrong with the actual physics/math, but right now I just want it to integrate. Here is the output I get when I run the script:

8.05359718208634e-5*x/(-6.28318530717959*x + 0.000935483870967742)
Traceback (most recent call last):
  File "script.py", line 34, in <module>
    integrate(ig*x,x)
  File "C:\Python27\lib\site-packages\sympy\utilities\decorator.py", line 24, in threaded_func
    return func(expr, *args, **kwargs)
  File "C:\Python27\lib\site-packages\sympy\integrals\integrals.py", line 847, in integrate
    return integral.doit(deep = False)
  File "C:\Python27\lib\site-packages\sympy\integrals\integrals.py", line 364, in doit
    antideriv = self._eval_integral(function, xab[0])
  File "C:\Python27\lib\site-packages\sympy\integrals\integrals.py", line 577, in _eval_integral
    parts.append(coeff * ratint(g, x))
  File "C:\Python27\lib\site-packages\sympy\integrals\rationaltools.py", line 42, in ratint
    g, h = ratint_ratpart(p, q, x)
  File "C:\Python27\lib\site-packages\sympy\integrals\rationaltools.py", line 124, in ratint_ratpart
    H = f - A.diff()*v + A*(u.diff()*v).quo(u) - B*u
  File "C:\Python27\lib\site-packages\sympy\core\decorators.py", line 75, in __sympifyit_wrapper
    return func(a, sympify(b, strict=True))
  File "C:\Python27\lib\site-packages\sympy\polys\polytools.py", line 3360, in __mul__
    return f.mul(g)
  File "C:\Python27\lib\site-packages\sympy\polys\polytools.py", line 1295, in mul
    _, per, F, G = f._unify(g)
  File "C:\Python27\lib\site-packages\sympy\polys\polytools.py", line 377, in _unify
    F = f.rep.convert(dom)
  File "C:\Python27\lib\site-packages\sympy\polys\polyclasses.py", line 277, in convert
    return DMP(dmp_convert(f.rep, f.lev, f.dom, dom), dom, f.lev)
  File "C:\Python27\lib\site-packages\sympy\polys\densebasic.py", line 530, in dmp_convert
    return dup_convert(f, K0, K1)
  File "C:\Python27\lib\site-packages\sympy\polys\densebasic.py", line 506, in dup_convert
    return dup_strip([ K1.convert(c, K0) for c in f ])
  File "C:\Python27\lib\site-packages\sympy\polys\domains\domain.py", line 85, in convert
    raise CoercionFailed("can't convert %s of type %s to %s" % (a, K0, K1))
sympy.polys.polyerrors.CoercionFailed: can't convert DMP([1, 0], ZZ) of type ZZ[_b1] to RR
[Finished in 0.3s with exit code 1]

EDIT:
Alright, so I pulled out the numbers that the program was using and put it in wolfram alpha. Turns out that the integral doesn’t converge, hence the error. I guess it WAS just a math error.

  • 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-08T06:31:51+00:00Added an answer on June 8, 2026 at 6:31 am

    It is a very bad idea to use a symbolic library for numerical work. Just use scipy/numpy. That being said, for such a simple integral you could have used sympy. However you should actually use sympy expressions, not dump everything in opaque functions.

    Firstly, learn how do variables in python work:

    ig = Symbol('ig')
    ig = flux(x, I, r)
    

    After this operation ig is not a Symbol any more, it is just the return value of flux.

    Define all your symbols and then make an expression out of them. The integral is sufficiently simple for sympy to handle it.

    Finally, integral as simple as const*x/(x-const) as in your case should be done by hand, not wasted on software.

    [EDIT]: I have rewritten it cleanly, and still sympy does not integrate correctly because of a bug. You could report it on the mailing list or issue tracker and they will try to correct it. That being said, the expression is so simple that it can be integrated by hand.

    [EDIT2]:

    In [5]: integrate(a*x/(b*x+c), x)
    Out[5]: 
    
      ⎛         ⎛ 2        ⎞⎞
      ⎜x   c⋅log⎝b ⋅x + b⋅c⎠⎟
    a⋅⎜─ - ─────────────────⎟
      ⎜b            2       ⎟
      ⎝            b        ⎠
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently using: @^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&amp;%\$#_]*)?$ How can i make http:// not compulsory but if it does
Im currently using codeigniter to build a messaging system and im trying to stay
currently using spring 'exposedContextBeanNames' to allow me to display properties in my view but
Currently using Telerik ASP .NET MVC Controls version 2011.2.712 Hello all, I am trying
Currently using Oracle/BEA/Plumtree ALUI Portal 6.1, and am trying to display a client's IP
Im currently using jquery to link all td's to the edit link but i
I`m currently using: <%= f.time_select :day,:default => Time.now, :ampm => true, :minute_step => 15
I am currently using a datareader as the source but I want to instead
I'm currently learning to use SymPy. It seems interesting and useful, but I haven't
am currently using google feed api to get feed links dynamically. am trying to

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.