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

  • 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 ) – mikuszefski Mar 02 '20 at 07: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: https://stackoverflow.com/questions/44706092/how-to-convert-an-user-input-into-a-function-in-python-2-7 – Fabrizio Mar 02 '20 at 13:20

0 Answers0