0

This is the code

from sympy import *
from sympy.abc import x,n
fx=input("Function ")
ao = (1/pi)*(integrate(fx,(x,-pi, pi)))
print("ao= ",ao)
an = (1/pi)*integrate(fx*(cos(2*n*x)),(x,-pi,pi))
print("an= ",an)
bn = (1/pi)*integrate(fx*sin(2*n*x),(x,-pi,pi))
print("bn= ",bn)

When I try with the function x or some other it doesnt work. The error is TypeError: can't multiply sequence by non-int of type 'cos' I dont fully understand why that error occurs, please tell me what is my mistake

asked Mar 2, 2020 at 3:46
2
  • That's python 3 I guess. Can you give a proper traceback and your sympy version. as in 1.4 on python 2.7 I don't see a problem. (Top Tip...try to avoid import * only import what you need ) Commented Mar 2, 2020 at 7:25
  • Your input IS NOT a function. Your input is just a string. That's why you get that error. You need a smart way to convert your string to a mathematical function. Here there is a start: stackoverflow.com/questions/44706092/… Commented Mar 2, 2020 at 13:20

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.