機械学習の基礎１ 微分・積分メモ

機械学習の基礎（微分・積分）を備忘録として残しておく

#1.対数公式
① $ log_aa = 1$
② $ log_a1 = 0$
③ $log_aMN = log_aM + log_aN$
④ $ \displaystyle log_a \{\frac{M}{N}} = log_aM - log_aN $
⑤ $ log_aM^r = rlog_aM$


#2.微分の公式
① $(x^n+c)' = nx^{n-1} $
② $(f(x)・g(x))' = f'(x)・g(x)+f(x)・g'(x)$
③ $\displaystyle \left[ {\frac{f(x)}{g(x)}}\right]'= {\frac{f'(x)・g(x)-f(x)・g'(x))}{g(x)^2}} $
④ $(e^x)' = e^x$
⑤ $(log(x))' = {\frac{1}{x}}$
⑥ $\displaystyle {\frac{dy}{dx}}={\frac{dy}{du}}・{\frac{du}{dx}}$ 　（y = f(u), u = g(x)の時）

#3.積分の公式
① $\displaystyle  \int^b_a (x^n+c) dx = \left[ \frac{1}{n+1}x^{n+1} + cx\right]^b_a $
② $\displaystyle  \int^b_a f(x) dx = \int^β_α f(g(t)) {\frac{dx}{dt}}dt $

③ $\displaystyle  \int^b_a f'(x)g(x) dx = \left[ f(x)g(x)\right]^b_a-\int^b_a f(x) g'(x)dx $

④ $\displaystyle  \int^b_a f(x)g'(x) dx = \left[ f(x)g(x)\right]^b_a-\int^b_a f'(x) g(x)dx $

#4.微分の演習
**1) $f(x) = 3x^4 - 2x^3 + 4x -5$**
   >$f'(x)= 12x^3 - 6x^2 + 4$ 

**2) $f(x) = (x^2 + 2x - 3) (2x - 1)$**
   >$f'(x)=(x^2 + 2x - 3)'(2x - 1) + (x^2 + 2x - 3) (2x - 1)'$ 
　　　　$ = (2x + 2)(2x - 1) + (x^2 + 2x - 3)・2 $
　　　　$ = 4x^2 + 2x - 2 + 2x^2 + 4x - 6 $
　　　　$ = 6x^2 + 6x - 8 $

**3)$\displaystyle f(x) = \frac{2x + 5}{x^2 + 1} $**　　
>$\displaystyle f'(x) = \frac{(2x + 5)'(x^2 + 1) - (2x + 5)(x^2 + 1)'}{(x^2 + 1)^2} $
　　　　$\displaystyle = \frac{2(x^2 + 1) - (2x + 5)・2x}{(x^2 + 1)^2} $
　　　　$\displaystyle = \frac{2x^2 + 2 - 4x^2 - 10x}{(x^2 + 1)^2} $
　　　　$\displaystyle = \frac{-2x^2 - 10x + 2}{(x^2 + 1)^2} $  


**4)$ f(x) = (2x^3-x-1)^3 $**　
>$u = 2x^3-x-1$と置くと、
$\displaystyle f'(x) = \frac{df(x)}{du}・\frac{du}{dx} $
　　　　$ = (u^3)'(2x^3-x-1)' $
　　　　$ = 3u^2(6x^2-1) $
　　　　$ = 3(2x^3-x-1)^2(6x^2-1) $  
    
**5)$f(x)=\sqrt[4]{x^5}$**
>$\displaystyle f'(x) = (x^{\frac{5}{4}})' $
　　　　$\displaystyle = \frac{5}{4}x^{\frac{5}{4} - 1} $
　　　　$\displaystyle = \frac{5}{4}x^{\frac{1}{4}} $
　　　　$\displaystyle = \frac{5}{4}\sqrt[4]{x} $  

**6) $ f(x) = \sqrt{2x^2 - 3} $**　
>$\displaystyle f'(x) = ((2x^2 - 3)^\frac{1}{2})' $
　　　　$\displaystyle = \frac{1}{2}(2x^2 - 3)^{\frac{1}{2}-1} (2x^2 - 3)'$
　　　　$\displaystyle = \frac{1}{2}(2x^2 - 3)^{-\frac{1}{2}}・4x$
　　　　$\displaystyle = 2x(2x^2 - 3)^{-\frac{1}{2}}$
　　　　$\displaystyle = \frac{2x}{(2x^2 - 3)^\frac{1}{2}}$
　　　　$\displaystyle = \frac{2x}{\sqrt{2x^2 - 3}}$  
    
**7) $ f(x) = (log x)^2 $**
>$ f'(x) = 2(log x)(log x)' $
　　　　$\displaystyle = 2log x\frac{1}{x}$
　　　　$\displaystyle = \frac{2log x}{x}$  
    
**8)$ f(x) = x(log x) $** 
>$ f'(x) = x'(log x) + x(log x)' $
　　　　$\displaystyle = 1・(log x) + x・\frac{1}{x}$
　　　　$ = log x +1$  

**9) $ f(x) = e ^ {-3x}$**
>$ f'(x) = e ^ {-3x}・(-3x)'$
　　　　$ = -3e^{-3x}$  

**10)$ f(x) = xe ^ x$**
>$ f'(x) = x'e ^ x + x(e ^ x)'$
　　　　$ = e^x + xe^x$

#5.偏微分の演習
**1) $ z = x^2 -3xy + 2y^2 $**
>$\displaystyle \frac{\partial z}{\partial x} = 2x - 3y $
$\displaystyle \frac{\partial z}{\partial y} = -3x + 4y $



**2) $\displaystyle z = \frac{x-y}{x+y} $**
>$\displaystyle \frac{\partial z}{\partial x} = \frac{(x-y)'(x+y) - (x-y)(x+y)'}{(x+y)^2} $
　　$\displaystyle =  \frac{1・(x+y) - (x-y)・1}{(x+y)^2} $
　　$\displaystyle =  \frac{2y}{(x+y)^2} $

>$\displaystyle \frac{\partial z}{\partial y} = \frac{(x-y)'(x+y) - (x-y)(x+y)'}{(x+y)^2} $
　　$\displaystyle =  \frac{-1・(x+y) - (x-y)・1}{(x+y)^2} $
　　$\displaystyle =  \frac{-2x}{(x+y)^2} $



**3) $ z = \sqrt{3x-4y} $**  

>$\displaystyle \frac{\partial z}{\partial x} = ((3x-4y)^\frac{1}{2})' $
　　$\displaystyle =  \frac{1}{2}(3x-4y)^{-\frac{1}{2}}・3 $
　　$\displaystyle =  \frac{3}{2\sqrt{3x-4y}} $

>$\displaystyle \frac{\partial z}{\partial y} = ((3x-4y)^\frac{1}{2})' $
　　$\displaystyle =  \frac{1}{2}(3x-4y)^{-\frac{1}{2}}・(-4) $
　　$\displaystyle =  \frac{-2}{\sqrt{3x-4y}} $



4) $ z = e^{xy} $
>$\displaystyle \frac{\partial z}{\partial x} = e^{xy}・y $
　　$ =  ye^{xy} $

>$\displaystyle \frac{\partial z}{\partial y} = e^{xy}・x $
　　$ =  xe^{xy} $


**5) $ z = log (x - y) $**  
>$\displaystyle \frac{\partial z}{\partial x} = \frac{1}{x-y} $  

>$\displaystyle \frac{\partial z}{\partial y} = \frac{-1}{x-y} $ 

#5.積分の演習
**1) $\displaystyle  \int^2_1 x^2 dx $**
>$\displaystyle =  \left[ \frac{1}{3}x^3 \right]^2_1 $
$\displaystyle =  (\frac{1}{3}・2^3) - (\frac{1}{3}・1^3)  $
$\displaystyle =  \frac{8}{3} - \frac{1}{3} $
$\displaystyle =  \frac{7}{3} $


  
**2) $\displaystyle  \int^1_0 (x^4 + 4x^3 + 2x^2 - x + 5)dx $**  
>$\displaystyle = \left[ \frac{1}{5}x^5 + x^4 + \frac{2}{3}x^3 - \frac{1}{2}x^2 + 5x \right]^1_0 $
 $\displaystyle =  \frac{1}{5} + 1 + \frac{2}{3} - \frac{1}{2} + 5 $
 $\displaystyle =  \frac{191}{30} $  
 
 
**3)$\displaystyle \int^1_0 (2x + 1)^4 dx $**
>$\displaystyle u = 2x + 1$　と置くと、 $ \frac{du}{dx} = 2$  
$\displaystyle dx = \frac{du}{2} $
また、x=0の時、u=1。x=1の時、u=3。
よって、

>$\displaystyle \int^1_0 (2x + 1)^4 dx $
$\displaystyle = \int_1^3 u^4 \frac{du}{2} $
$\displaystyle  =\frac{1}{2} \left[ \frac{1}{5}u^5 \right]^3_1 $
$\displaystyle  =\frac{1}{2} (\frac{1}{5}・3^5 - \frac{1}{5}・1^5) $
$\displaystyle  =\frac{121}{5} $  
  
**4) $\displaystyle  \int_0^1 \int_0^1 xy dxdy $**
>$\displaystyle \int_0^1 xy dx$  について解くと、
$\displaystyle= \left[\frac{x^2y}{2}  \right]^1_0 $
$\displaystyle= \frac{y}{2} $  
よって、　　
$\displaystyle   \int_0^1 \int_0^1 xy dxdy $
$\displaystyle= \int_0^1 \frac{y}{2} dy $
$\displaystyle= \left[\frac{y^2}{4} \right]^1_0 $
$\displaystyle = \frac{1}{4} $