メニューバーの歯車マークのプルダウンメニュー→「Preview in Viewer pain」にチェックをいれるとペイン内にドキュメントが表示されるようになる。
メニューバーの「knit on Save」にチェックをいれると保存したときにドキュメントを生成する。
\(f(x)=x^2, 0 \le x \le 1とx軸で囲まれる面積\)
\[ \int_0^1 f(x) dx = \int_0^1 x^2 dx = \left[\frac{1}{3}x^3\right]_0^1=\frac{1}{3}=0.33\cdots \]
<- function(x) x^2
f integrate(f, 0, 1)
## 0.3333333 with absolute error < 3.7e-15
一行で書く場合
integrate(function(x) x^2, 0, 1)
## 0.3333333 with absolute error < 3.7e-15
グラフ
<- seq(-1, 2, 0.01)
x matplot(x = x, y = f(x), type = "l", col = "blue")
abline(v = c(0, 1), col = gray(0.2), lty = 2)
from scipy import integrate
def f(x):
return x**2
0, 1) integrate.quad(f,
## (0.33333333333333337, 3.700743415417189e-15)
一行で書く場合
lambda x: x**2, 0, 1) integrate.quad(
## (0.33333333333333337, 3.700743415417189e-15)
\[ f(x) = e^{-x}\\ 1 \le x \le \infty \] 無限大の積分記号(Inf)を使う。
<- function(x) exp(-x)
f integrate(f, 1, Inf)
## 0.3678794 with absolute error < 2.1e-05
<- seq(1, 10, 0.1)
x
matplot(x = x, y = f(x), type = "l")
グラフ描画練習
<- function(x) 1/(x^2 - 4)
f
<- seq(-5, 5, 0.1)
x
matplot(x = x, y = f(x), xlim = c(-5, 5), type = "l", col = "blue")
abline(h = seq(-5, 5, 1), v = seq(-5, 5, 1), col = gray(0.2), lty = 2)
abline(h = 0, v = 0)
abline(v = c(-2, 2), col = "red")