Vorlesung vom 08.12.2022
© 2022 Prof. Dr. Rüdiger W. Braun
from sympy import *
init_printing()
x = S('x')
y = S('y')
b = sin(x) + sin(y)
b
b.trigsimp()
Wir hätten gerne eine Darstellung als Produkt
b.trigsimp(method='fu')
Wie kompliziert ist dieser Ausdruck?
b.count_ops()
b.count_ops(visual=True)
def my_measure(expr):
opc = expr.count_ops(visual=True)
print(opc) # zur Fehlersuche
strafe = {}
strafe['ADD'] = 1
strafe['SIN'] = 1
strafe['MUL'] = -100 # negative Strafe = Belohnung
return opc.subs(strafe)
my_measure(b)
ADD + 2*SIN
# b.trigsimp(method='fu', measure=my_measure) # TypeError
def my_measure(expr):
opc = expr.count_ops(visual=True)
# print(opc) # zur Fehlersuche
strafe = {}
strafe['ADD'] = 1
strafe['SIN'] = 1
strafe['MUL'] = -100
strafe['COS'] = 1
strafe['DIV'] = 1
strafe['SUB'] = 1
return opc.subs(strafe)
c = b.trigsimp(method='fu', measure=my_measure)
c
my_measure(c)
c.trigsimp()
d = sin(x)**8
d.trigsimp()
def my_measure(expr):
opc = expr.count_ops(visual=True)
# print(opc) # zur Fehlersuche
strafe = {}
strafe['ADD'] = 1
strafe['SIN'] = 100
strafe['MUL'] = 1
strafe['COS'] = 1
strafe['DIV'] = 1
strafe['SUB'] = 1
strafe['POW'] = 1
return opc.subs(strafe)
d.trigsimp(method='fu', measure=my_measure)
x = S('x')
f = cos(2*x)
f.series(x, n=12)
f.series(x, pi/4)
f.subs(x, pi/4)
Die Reihe ist richtig, sie ist nur dämlich hingeschrieben
g = 1/(x**2+x+1)
g
gs = g.series(x, oo)
gs
h = exp(x)
h.series(x, -oo, n=25)
h.series(x, oo)
exp(sqrt(x+1)).series(x, oo)
r = exp(sqrt(x+1)-sqrt(x))
r
r_ser = r.series(x, oo, n=3)
r_ser
(sqrt(x)*(r-1)).limit(x, oo)
a = S('a')
b_ser = log(sqrt(x+a)).series(x, oo)
b_ser
b_ser.removeO()
reihe = x + 9 + 100/x + O(1/x**2, (x,oo))
reihe
(reihe**2).expand()
glg = Eq(log(x), x + log(y))
glg
lsg = solve(glg, x)
lsg
f = lsg[0]
f_ser = f.series(y, 0)
f_ser
g1 = glg.subs(x, f_ser)
g1
l_ser = g1.lhs.series(y, 0)
l_ser
r_ser = g1.rhs.series(y, 0)
r_ser
series(log(1+y))
l_ser - r_ser
v = Matrix([1,2,3])
v
w = Matrix(1,3,[4,5,6]) # 1x3-Matrix
w
v[1]
w[1]
v*w
w * v
A = Matrix(3,3,range(1,10))
A
A[1,0]
A[8]
???
A.row(1)
A.col(2)
A * v
# v * A # ShapeError
x = S('x')
y = S('y')
B = Matrix([[x,1], [1,y]])
B
x = symbols('x0:10')
x
x[7]
M = Matrix(2, 5, x)
M
a = symbols('a0:2_0:5')
A = Matrix(2, 5, a)
A