学習環境
微分積分学
(ちくま学芸文庫 )
(吉田
洋一 (著)、筑摩書房 )のⅢ.(平均値の定理)、1.(連続関数)、問1、2.の解答を求めてみる。
x
<
0
f
x
=
x
=
-
x
f
'
x
=
-
1
x
>
0
x
=
0
f
0
=
0
h
>
0
h
→
0
⇒
f
0
+
h
=
f
h
→
0
h
<
0
h
→
0
⇒
f
0
+
h
=
f
h
→
0
x
f
x
=
x
2
3
f
'
x
=
2
3
x
-
1
3
=
2
3
x
1
3
x
≠
0
x
=
0
f
0
=
0
2
3
=
0
h
→
0
⇒
f
0
+
h
=
h
2
3
=
h
2
1
3
→
0
コード
Python 3
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, Derivative, plot, solve, Rational, Limit
print ( '1.' )
x, h = symbols ( 'x, h' )
f = abs ( x)
g = x ** Rational ( 2 , 3 )
class MyTest ( TestCase):
def setUp ( self):
pass
def tearDown ( self):
pass
def test_abs ( self):
for d in [ '+' , '+' ]:
l = Limit ( f. subs ({ x: 0 + h}) - f. subs ({ x: 0 }), h, 0 , dir= d)
self. assertEqual ( l. doit (), f. subs ({ x: 0 }))
def test_cubic_root ( self):
for d in [ '+' , '+' ]:
l = Limit ( f. subs ({ x: 0 + h}) - f. subs ({ x: 0 }), h, 0 , dir= d)
self. assertEqual ( l. doit (), f. subs ({ x: 0 }))
print ( '2.' )
p = plot ( f,
ylim=(- 10 , 10 ),
legend= True,
show= False)
colors = [ 'red' , 'green' , 'blue' , 'brown' , 'orange' ,
'purple' , 'pink' , 'gray' , 'skyblue' , 'yellow' ]
for o, color in zip ( p, colors):
o. line_color = color
p. show ()
p. save ( 'sample1.png' )
if __name__ == '__main__' :
main ()
入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))
% ./sample1.py -v
1.
2.
test_abs (__main__.MyTest) ... ok
test_cubic_root (__main__.MyTest) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.016s
OK
%
0 コメント:
コメントを投稿