Vorlesung vom 13.10.2022
Copyright: Prof. Dr. Rüdiger W. Braun
4*3 + 5
17
4*(3+5)
32
(3+5)/4
2.0
(3+5)/5
1.6
9/5
1.8
2**10
1024
(1/3)*3
1.0
(1/3)**100 * 3**100
0.9999999999999944
from sympy import *
S(4)*3 + 5
(S(3)+5)/4
(S(3)+5)/5
Rational(8,5)
S("8/5")
S(8/5)
(S(1)/3)**100 * 3**100
(S(1)/3)**100
Sympy kennt alle elementaren und einige spezielle Funktionen
pi
sin(pi/6)
cos(pi/4)
sqrt(128)
_**2
atan(1)
atan(S(1)/2)
atan(1/2)
atan(1/sqrt(3))
exp(2)
log(1/exp(3))
log(e)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Input In [31], in <cell line: 1>() ----> 1 log(e) NameError: name 'e' is not defined
log(E)
factorial(5)
factorial(120)
factorial(240/7)
pi
N(pi)
N(pi, 100)
N(1/3, 100)
N("1/3", 100)
N(Rational(2,3), 100)
type(3)
int
type(S(3))
sympy.core.numbers.Integer
type(1/3)
float
type(N(S(1)/3, 200))
sympy.core.numbers.Float
type(S("8/5"))
sympy.core.numbers.Rational
type(pi)
sympy.core.numbers.Pi
Man muss manchmal den Typ eines Objekts wissen, um das Ergebnis zu verstehen. Man legt den Typ in der Regel aber implizit fest.
1/0
--------------------------------------------------------------------------- ZeroDivisionError Traceback (most recent call last) Input In [49], in <cell line: 1>() ----> 1 1/0 ZeroDivisionError: division by zero
11.**500
--------------------------------------------------------------------------- OverflowError Traceback (most recent call last) Input In [50], in <cell line: 1>() ----> 1 11.**500 OverflowError: (34, 'Result too large')
11**500
49698419673122668962869431655245562316047646973098768083125762994096192244203916170987083962253749489388688113714575561907503512837449875405039140440330009424543851341473661479835156198793475230001956315493079590327474913873798690064481533085354154735423096767027003741096784021844432989065936384717922119162319032031586803190801094405732340227101653875034599110559882607618553240212695425973141414122679894203387024067292317607709706656265698204172143249895717068799024075072923130694160791083167647986127226561792230001
N(11.)**500
N(11., 550)**500
a = 5
a
5
b
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Input In [56], in <cell line: 1>() ----> 1 b NameError: name 'b' is not defined
b = a
b
5
a = 19
b
5
x = S('x')
x
type(x)
sympy.core.symbol.Symbol
f = 5*x + 13
f
x = 0
f
x = S('x')
sin(x)**2 + cos(x)**2
Simplify
s = sin(x)**2 + cos(x)**2
simplify(s)
s = sqrt(x**2)
s
simplify(s)
sympy hat Recht und Sie haben Unrecht 🙂
x = -2
x == sqrt(x**2)
False
x, sqrt(x**2)
(-2, 2)