from sympy import *
init_printing()
t = symbols('t')
x = cos(t)+t*sin(t)
y = sin(t)-t*cos(t)
from sympy import *
from sympy.plotting import plot_parametric
p = plot_parametric(x,y,(t,-2*pi,2*pi), show=False)
p.show()
dx_dt = diff(x,t)
dy_dt = diff(y,t)
dy_dx = dy_dt/dx_dt
dy_dx
%matplotlib inline
from sympy import *
init_printing()
x = symbols('x')
f11=sin(x)*sin(x)
f23=sin(2*x)*sin(3*x)
f24=sin(2*x)*sin(4*x)
p = plot(f11, f23, f24, (x, -pi, pi), ylim=[-1,1],
legend=True, show=False)
p[0].line_color = 'b'
p[1].line_color = 'r'
p.show()
$n\neq m$の場合は,位相のずれのために$0\dots-\pi$あるいは$-\pi \dots 0$において正の図形と負の図形がちょうど同じとなるため,積分はゼロとなる.一方$n\neq m$の場合はそれぞれの領域で正となる図形しか現れない.従って,面積を有する.
from sympy import *
A=Matrix([[1,0,-2],[0,2,0],[-2,0,1]])
B=Matrix([[3,0,2],[0,-3,0],[2,0,3]])
pprint(B)
⎡3 0 2⎤ ⎢ ⎥ ⎢0 -3 0⎥ ⎢ ⎥ ⎣2 0 3⎦
A*B
B*A
PA,D = A.diagonalize()
pprint(PA)
PA.T*A*PA
⎡1 0 -1⎤ ⎢ ⎥ ⎢0 1 0 ⎥ ⎢ ⎥ ⎣1 0 1 ⎦
PB,D = B.diagonalize()
pprint(PB)
PB.T*B*PB
⎡0 -1 1⎤ ⎢ ⎥ ⎢1 0 0⎥ ⎢ ⎥ ⎣0 1 1⎦
PA.T*B*PA
PAとPBでは行列の列要素が食い違っている.しかし,行列の固有値には順番がないので,食い違いは問題なく,どちらの直交化行列PA, PBを使ってもA,Bは同時に対角化される.
from sympy import *
A = Matrix([[3,2,2],[2,2,0],[2,0,4]])
A
x,y,z = symbols('x y z')
xx = Matrix([x,y,z])
expand(xx.T*A*xx)
P,D = A.diagonalize()
P
c0=P[:,0]/P[:,0].norm()
c1=P[:,1]/P[:,1].norm()
c2=P[:,2]/P[:,2].norm()
PP = c0.col_insert(1,c1).col_insert(2,c2)
PP
Py = (PP*xx)
Py.T
expand(Py.T*A*Py)
from sympy import *
init_session()
a,b,c, x = symbols('a b c x')
IPython console for SymPy 1.0 (Python 3.6.1-64-bit) (ground types: python) These commands were executed: >>> from __future__ import division >>> from sympy import * >>> x, y, z, t = symbols('x y z t') >>> k, m, n = symbols('k m n', integer=True) >>> f, g, h = symbols('f g h', cls=Function) >>> init_printing() Documentation can be found at http://docs.sympy.org/1.0/
a_b_c = 1
ab_bc_ca = -2
abc = -1
expand((a+b+c)**2-2*(a*b+b*c+c*a))
a2_b2_c2 = a_b_c**2-2*ab_bc_ca
a2_b2_c2
ア, これをa2_b2_c2とする.
together(1/a+1/b+1/c)
a1_b1_c1 = ab_bc_ca/abc
a1_b1_c1
イ, a1_b1_c1とする.
expand((1/a+1/b+1/c)**2)
together(2/(b*c)+2/(a*c)+2/(a*b))
expand((1/a+1/b+1/c)**2-(2/(b*c)+2/(a*c)+2/(a*b)))
ウ,a12_b12_c12とする.
a12_b12_c12 = a1_b1_c1**2 - 2*(a_b_c)/(abc)
a12_b12_c12
collect(expand((a*x-1/a)**2+
(b*x-1/b)**2+
(c*x-1/c)**2),x)
A = a2_b2_c2 * x**2 -6*x + a12_b12_c12
A
solve(A-7,x)
こいつはどうしようもない.Aの中に浮動小数点数が入っているので,解析的に求められない.整数の式に書き直して解く.
solve(5*x**2-6*x-6-7,x)
from sympy import *
init_session()
a,b,c, x = symbols('a b c x')
IPython console for SymPy 1.0 (Python 3.6.1-64-bit) (ground types: python) These commands were executed: >>> from __future__ import division >>> from sympy import * >>> x, y, z, t = symbols('x y z t') >>> k, m, n = symbols('k m n', integer=True) >>> f, g, h = symbols('f g h', cls=Function) >>> init_printing() Documentation can be found at http://docs.sympy.org/1.0/
a_b_c = 1.1
ab_bc_ca = -2.2
abc = -1.1
expand((a+b+c)**2-2*(a*b+b*c+c*a))
a2_b2_c2 = a_b_c**2-2*ab_bc_ca
a2_b2_c2
ア, これをa2_b2_c2とする.
together(1/a+1/b+1/c)
a1_b1_c1 = ab_bc_ca/abc
a1_b1_c1
イ, a1_b1_c1とする.
expand((1/a+1/b+1/c)**2)
together(2/(b*c)+2/(a*c)+2/(a*b))
expand((1/a+1/b+1/c)**2-(2/(b*c)+2/(a*c)+2/(a*b)))
ウ,a12_b12_c12とする.
a12_b12_c12 = a1_b1_c1**2 - 2*(a_b_c)/(abc)
a12_b12_c12
collect(expand((a*x-1/a)**2+
(b*x-1/b)**2+
(c*x-1/c)**2),x)
A = a2_b2_c2 * x**2 -6*x + a12_b12_c12
A
solve(A-7,x)