from sympy import *
init_session()
A=Matrix([[2,1,1,-4],[-1,0,2,-2],[0,1,-2,1]])
A
IPython console for SymPy 1.6.1 (Python 3.8.3-64-bit) (ground types: gmpy) 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 https://docs.sympy.org/1.6.1/
A.rref()
$A=\left( \begin{array}{@{\,}cccc@{\,}} 1 & 0 & -1 & -2\\ -2 & 1 & 3 & 5\\ 1 & 1 & 0 & -1 \end{array} \right)$ とする.$R^4$から$R^3$への線形写像$f$を $f(x)=Ax$で 与えるとき,$f$のIm$f$およびKer$f$の次元と1組の基底を求めよ.
from sympy import *
init_session()
A=Matrix([[1,0,-1,-2],[-2,1,3,5],[1,1,0,-1]])
A
IPython console for SymPy 1.6.1 (Python 3.8.3-64-bit) (ground types: gmpy) 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 https://docs.sympy.org/1.6.1/
A.rref()
A.nullspace()
from sympy import *
init_session()
f = exp(-x**2)
f
IPython console for SymPy 1.6.1 (Python 3.8.3-64-bit) (ground types: gmpy) 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 https://docs.sympy.org/1.6.1/
df = f.diff(x)
df
df2 = f.diff(x,x)
df2
%matplotlib inline
plot(f,df,df2,(x,-5,5))
<sympy.plotting.plot.Plot at 0x7fde72ef2040>
solve(df,x)
solve(df2,x)
x | $-\infty$ | $\cdots$ | $-\frac{\sqrt{2}}{2}$ | $\cdots$ | 0 | $\cdots$ | $\frac{\sqrt{2}}{2}$ | $\cdots$ | $\infty$ |
---|---|---|---|---|---|---|---|---|---|
f(x) | 0 | $\nearrow$ | $\nearrow$ | $\nearrow$ | 1.0 | $\searrow$ | $\searrow$ | $\searrow$ | 0 |
f'(x) | 0 | + | + | + | 0 | - | - | - | 0 |
f''(x) | 0 | + | 0 | - | - | - | 0 | + | 0 |
関数 \begin{equation*} f(x) = \frac{1}{\cos x + 1} \end{equation*} の不定積分を求めよ.また,$x=0..\pi/2$の定積分を求めよ.
from sympy import *
init_session()
1/(cos(x)+1)
IPython console for SymPy 1.6.1 (Python 3.8.3-64-bit) (ground types: gmpy) 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 https://docs.sympy.org/1.6.1/
integrate(1/(cos(x)+1),x)
integrate(1/(cos(x)+1),(x,0,pi/2))
(2017大学入試センター試験 追試験 数学II・B 第2問)
関数$f(x)=x^3-5x^2+3x-4$について考える. 関数$f(x)$の増減を調べよう.$f(x)$の導関数は \begin{equation*} f'(x) = \fbox{ ア }\,x^2 - \fbox{ イウ }\,x + \fbox{ エ } \end{equation*} であり.$f(x)$は$x=\frac{\fbox{ オ }}{\fbox{ カ }}$で極大値, $x=\fbox{ キ }$で極小値をとる. よって,$x \geqq 0$の範囲における$f(x)$の最小値は$\fbox{ クケコ }$ である.
また,方程式$f(x)=0$の異なる実数解の個数は$\fbox{ サ }$個である.
from sympy import *
init_session()
IPython console for SymPy 1.6.1 (Python 3.8.3-64-bit) (ground types: gmpy) 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 https://docs.sympy.org/1.6.1/
aa=1
f= aa*x**3-5*x**2+3*x-4
f
df = diff(f,x)
df
s1=solve(df,x, dict=true)
s1
f.subs(s1[0])
f.subs(s1[1])
x0=0
m = df.subs({x:x0})
yl=m*x+f.subs({x:x0})
yl
%matplotlib inline
from sympy import *
plot(f,yl,(x,-2,4))
<sympy.plotting.plot.Plot at 0x7fde730dd280>
曲線$y=f(x)$上の点$(0, f(0))$における接線を$l$とすると, $l$の方程式は$y=\fbox{ シ }\,x - \fbox{ ス }$である. また,放物線$y=x^2+px+q$を$C$とし, $C$は点$(a, \fbox{ シ }\,a - \fbox{ ス })$で $l$と接しているとする. このとき,$p,q$は$a$を用いて \begin{equation*} p = \fbox{ セソ }\, a + \fbox{ タ }\,, q = a^{\fbox{ チ }} - \fbox{ ツ } \end{equation*} と表される.
a, p, q = symbols('a, p,q')
g=x**2+p*x+q
g
eq1=g.subs({x:a})-yl.subs({x:a})
eq1
eq2=g.diff(x).subs({x:a})-m
eq2
s2=solve(eq2,p,dict=true)
s2[0]
solve(eq1.subs(s2[0]),q)
問3.において, 関数$f(x)=1.1x^3-5x^2+3x-4$, また,曲線$y=f(x)$上の点$(0.1, f(0.1))$における接線を$l$として問題を解け. $\fbox{ ツ }$は3.9522となる.
from sympy import *
init_session()
IPython console for SymPy 1.6.1 (Python 3.8.3-64-bit) (ground types: gmpy) 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 https://docs.sympy.org/1.6.1/
aa=1.1
f= aa*x**3-5*x**2+3*x-4
f
df = diff(f,x)
print("f'(x):",df)
f'(x): 3.3*x**2 - 10*x + 3
s1=solve(df,x, dict=true)
print("極大,極小 : ",s1)
極大,極小 : [{x: 0.337614592259064}, {x: 2.69268843804397}]
f.subs(s1[0])
print("最小値:", f.subs(s1[1]))
最小値: -10.6989081645382
%matplotlib inline
from sympy import *
plot(f,yl,(x,-2,4))
<sympy.plotting.plot.Plot at 0x7fde7345dfa0>
x0=0.1
m = df.subs({x:x0})
print("接線の傾き:", m)
#yl=m*x+f.subs({x:x0}) # HERE!!!
yl=m*(x-x0)+f.subs({x:x0})
print("lの方程式:",yl)
接線の傾き: 2.03300000000000 lの方程式: 2.033*x - 3.9522
a, p,q = symbols('a, p,q')
g=x**2+p*x+q
g
eq1=g.subs({x:a})-yl.subs({x:a})
print("接線の方程式:",eq1)
接線の方程式: a**2 + a*p - 2.033*a + q + 3.9522
eq2=g.diff(x).subs({x:a})-m
print("a,pの満たすべき方程式:",eq2)
a,pの満たすべき方程式: 2*a + p - 2.033
s2=solve(eq2,p,dict=true)
print("p:",s2[0])
p: {p: 2.033 - 2.0*a}
s3 = solve(eq1.subs(s2[0]),q)
print("q:",s3)
q: [a**2 - 3.9522]