ich habe mit Piecewise eine Funktion (Rechteckimpuls) erstellt und möchte diese Plotten.
Code: Alles auswählen
import sympy
from sympy import *
from sympy.mpmath import *
from sympy.plotting import *
from sympy.abc import x, y, z, p, r, w
from IPython.display import display
a, b = -1.5, 1.5
I = [a,b]
m = (2 * pi)/(b-a)
p = Function('p')
f = Function('f')
p = sympy.Piecewise((0,w>1),(0,w<-1),(1,True))
f = lambda u: p.subs(w,u)
def ff(n):
k = 0
c, s = fourier(f, I, n)
fkt = 0
while k <= n:
fkt += c[k]*sympy.cos(k*m*x) + s[k]*sympy.sin(k*m*x)
#fkt += c[k]*x + s[k]*x
k += 1
return fkt
plot(ff(10),f(x),(x,a,b))
Beim Einsetzen einzelner Werte funktioniert es, auch das Plotten der zugehörigen Fourierreihe haut hin.TypeError: unorderable types: complex() < int()
Für jegliche Hilfe wär ich sehr dankbar!