#!/usr/bin/env python # coding: utf-8 # # Table of Contents #

1  連立方程式
2  展開(expand) 因数分解(factor)
3  3点を通る2次方程式
# In[3]: from sympy import Symbol, pprint a = 3 b = 2 pprint(a+b) # In[7]: x = Symbol('x') eq1 = a*x+b pprint(eq1) # In[8]: from sympy import solve solve(eq1, x) # # 連立方程式 # # In[9]: from sympy import Matrix, solve_linear_system from sympy.abc import x, y system = Matrix(( (1, 4, 2), (-2, 1, 14))) solve_linear_system(system, x, y) # # 展開(expand) 因数分解(factor) # In[13]: from sympy import * pprint(expand((x+y)**2)) # In[15]: pprint(factor(x**3 - x**2 + x - 1)) # # 3点を通る2次方程式 # 3点(1,2),(-3,4),(-1,1)を通る2次方程式を求めよ. # In[33]: from sympy import * f, x, a, b, c = symbols('f x a b c') f = a*x**2 + b*x + c # In[34]: print(f) # In[35]: class my_func(Function): @classmethod def eval(cls, x): return a*x**2 + b*x + c # In[36]: pprint(my_func(x)) # In[37]: eq1 = my_func(1) eq2 = my_func(-3) eq3 = my_func(-1) # In[38]: pprint(eq1) pprint(eq2) pprint(eq3) # In[40]: from sympy.abc import a, b, c system = Matrix(( (1, 1, 1, 2), (9, -3, 1, 4), (1, -1, 1, 1))) s1 = solve_linear_system(system, a, b, c) # In[42]: pprint(s1) # In[48]: pprint(s1[a]) pprint(s1[b]) pprint(s1[c]) # In[52]: from sympy import sin eq = sin(x+1) - x**2 # In[54]: solve(eq, x) # In[ ]: