Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve a polynomial expression in python3.5?

Tags:

python-3.5

from __future__ import division
import math
from sympy import *
d=symbol('d')
x=solve(d**2 - 224*d + 400)
print(x)

Hi,I'm new to python.I just tried to solve a polynomial expression using symPy,but got the following error.

Traceback (most recent call last):
  File "C:/Windows/System32/test.py", line 4, in <module>
    d=symbol('d')
TypeError: 'module' object is not callable

Someone pls help me out with the correct function.Thank you


2 Answers

You're sure you are running python3, and your script is not named something that conflicts with any other modules? Do you have a file named sympy.py in your script's directory? (You shouldn't)

I never use import *, you never know what kind of namespace errors you'll run into. This code works 100% for me:

#!/usr/bin/env python3

import math
import sympy

d = sympy.Symbol('d')
x = sympy.solve(d**2 - 224*d + 400)
print(x)  # Prints [-4*sqrt(759) + 112, 4*sqrt(759) + 112]

x = sympy.solve(d - 10)
print(x)  # Prints 10
like image 130
Bryan Avatar answered Sep 07 '26 17:09

Bryan


capitalize Symbol and try again.

like image 26
Aydin Gerek Avatar answered Sep 07 '26 18:09

Aydin Gerek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!