Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168693
Image: ubuntu2004

Chain Rule

Suppose that f,gf, g are differentiable. And The derivative of compose of ff and gg, F=f(g(x))F=f(g(x)) is:

Formula:

                 
ddxF(x) \frac{d}{d x}F(x) =  ddxf(g(x)))\frac{d}{d x} f(g(x)))
    =  ddg(x)\frac{d}{d g(x)} f(g(x))f(g(x))dg(x)dx\frac{ dg(x)}{d x}
    =  f(u)u(x)f'(u) • u'(x)
    =  f(g(x))g(x)f'(g(x)) g'(x)

 

Graphical Representation:

                 

 

 

g(x)g(x)   f(")f(")  
  xx \longrightarrow g(x)g(x) \longrightarrow

f(g(x))f(g(x))

    \downarrow   \downarrow  
    g(x)g'(x) ×\times f(")f'(")  
      \downarrow

f(g(x))g(x)f'(g(x))g'(x)

 


Usage:
    
ChainRule( f(u), g(x), x)
    
  f(u) : function of u=g(x)u=g(x)
  g(x) : function of xx
    x   : variable xx
Author: chu-ching huang
               Chang-gung University, Taiwan
             cchuang_AT_mail.cgu.edu.tw
# -*- coding: utf-8 -*- from sympy import * var('u x') def ChainRule(f,g,x): f=f g=g F=f.subs(u,g) html("============ <span style=\"color: #0000ff;\"><strong> Chain Rule (鍊鎖法則) </strong></span>=============") html('The derivative of \ <span style=\"color: #ff0000;\"><strong>$f(g(x))$</strong></span> \ =\ <span style=\"color: #335500;\"><strong>$%s$</strong></span>\ '%F) print '\nwith \t f(u)=%s \n \t u=g(x)=%s \nis' %(f,g) html('\t<span style=\"color: #336600;\"><strong>$f\'(g(x)) = %s$</strong></span>'%diff(F,x)) html('\nsince \ <span style=\"color: #ff0000;\"><strong>f\'(u)=%s</strong></span> \ and \ <span style=\"color: #ff0000;\"><strong> u\'(x)=%s</strong></span> \ '%(diff(f,u),diff(g,x))) print '\n==>\n' print ' dF(x)/dx \t= df(g(x))/dx = d(%s)/dx \n \ \t\t= df(u)/dx = d(%s)/dx\n \ \t\t= df(u)/du*du/dx \n\ \t\t= f\'(u) * u\'(x) = [%s]*[%s] \n \t\t= [%s]*[%s] \n \t\t= %s'\ %(F,f,diff(f,u),diff(g,x),diff(f,u).subs(u,g),diff(g,x),diff(F,x)) print "\nThe derivative of F(x) is:\n" pretty_print(diff(F,x)) print "\n" html('========= <span style=\"color: #0000ff;\"><strong> .oo000oo. End .oo000oo. </strong></span> ==========')
var('n') ChainRule(u^n,sin(x),x)
============ Chain Rule (鍊鎖法則) =============
The derivative of f(g(x)) = sin(x)**n
with f(u)=u**n u=g(x)=sin(x) is
f'(g(x)) = n*sin(x)**(-1 + n)*cos(x)
since f'(u)=n*u**(-1 + n) and u'(x)=cos(x)
==> dF(x)/dx = df(g(x))/dx = d(sin(x)**n)/dx = df(u)/dx = d(u**n)/dx = df(u)/du*du/dx = f'(u) * u'(x) = [n*u**(-1 + n)]*[cos(x)] = [n*sin(x)**(-1 + n)]*[cos(x)] = n*sin(x)**(-1 + n)*cos(x) The derivative of F(x) is: -1 + n n⋅sin (x)⋅cos(x)
========= .oo000oo. End .oo000oo. ==========
ChainRule(cos(u),x**3,x)
============ Chain Rule (鍊鎖法則) =============
The derivative of f(g(x)) = cos(x**3)
with f(u)=cos(u) u=g(x)=x**3 is
f'(g(x)) = -3*x**2*sin(x**3)
since f'(u)=-sin(u) and u'(x)=3*x**2
==> dF(x)/dx = df(g(x))/dx = d(cos(x**3))/dx = df(u)/dx = d(cos(u))/dx = df(u)/du*du/dx = f'(u) * u'(x) = [-sin(u)]*[3*x**2] = [-sin(x**3)]*[3*x**2] = -3*x**2*sin(x**3) The derivative of F(x) is: 2 ⎛ 3⎞ -3⋅x ⋅sin⎝x ⎠
========= .oo000oo. End .oo000oo. ==========
ChainRule(u**3,cos(x),x)
============ Chain Rule (鍊鎖法則) =============
The derivative of f(g(x)) = cos(x)**3
with f(u)=u**3 u=g(x)=cos(x) is
f'(g(x)) = -3*cos(x)**2*sin(x)
since f'(u)=3*u**2 and u'(x)=-sin(x)
==> dF(x)/dx = df(g(x))/dx = d(cos(x)**3)/dx = df(u)/dx = d(u**3)/dx = df(u)/du*du/dx = f'(u) * u'(x) = [3*u**2]*[-sin(x)] = [3*cos(x)**2]*[-sin(x)] = -3*cos(x)**2*sin(x) The derivative of F(x) is: 2 -3⋅cos (x)⋅sin(x)
========= .oo000oo. End .oo000oo. ==========
def ChainRule2(f,g,x): f=f g=g e='' F=f.subs(u,g) html("============ <span style=\"color: #0000ff;\"><strong> Chain Rule ('鍊鎖法則') </strong></span>=============") html('The derivative of \ <span style=\"color: #ff0000;\"><strong>$f(g(x))$</strong></span> \ =\ <span style=\"color: #335500;\"><strong>$%s$</strong></span>\ '%F) print '\n with \t f(u)=%s \n \t\t u=g(x)=%s \n' %(f,g) print '\n==>' print "\n" html('\t\t\t$%s$\t %10s  \t$%s$' %(g,e,f)) html('\t\t $x$ \t $\longrightarrow$ \t $%s$ \t $\longrightarrow$ \t $%s$' %(g,f.subs(u,g))) html('\t(<span style=\"color: #ff0000;\">diff</span>)\t\t  $ \downarrow$\t\t\t   $\downarrow$') html('<span style=\"color: #ff0000;\">\t\t\t$%10s$\t      \t$%10s$  </span>' %(g.diff(x),f.diff(u))) html('<span style=\"color: #336600;\">\t($u=%s$)\t\t  $\downarrow$</span>' %g) html('<span style=\"color: #0000ff;\">\t\t\t  $%s$*%s$</span>' %(g.diff(x),f.diff(u).subs(u,g))) html('\n========= <span style=\"color: #0000ff;\"><strong> .oo000oo. End .oo000oo. </strong></span> ==========')
ChainRule2(exp(u),-x^2,x)
============ Chain Rule ('鍊鎖法則') =============
The derivative of f(g(x)) = exp(-x**2)
with f(u)=exp(u) u=g(x)=-x**2 ==>
-x**2    exp(u)
x \longrightarrow -x**2 \longrightarrow exp(-x**2)
(diff)    \downarrow   \downarrow
-2*x      exp(u)  
(u=-x**2)   \downarrow
  -2*x*exp(-x**2)
========= .oo000oo. End .oo000oo. ==========
def ChainRule3(f,g,x): f=f g=g e='' F=f.subs(u,g) html("============ <span style=\"color: #0000ff;\"><strong> Chain Rule </strong></span>=============") html('The derivative of \ <span style=\"color: #ff0000;\"><strong>$f(g(x))$</strong></span> \ =\ <span style=\"color: #335500;\"><strong>$%s$</strong></span>\ '%F) print '\n with \t f(u)=%s \n \t\t u=g(x)=%s \n' %(f,g) print '\n==>' print "\n" html('<table style=\"width: 476px; height: 129px;\" border=\"0\">') html('<tbody>') html('<tr>') html('<td></td><td></td><td>$%s$</td>' %g) html('<td></td><td>$%s$</td>' %f) html('</tr>') html('<tr>') html('<td></td><td>$x$ </td><td>$\longrightarrow$</td><td> $%s$</td>' %g) html('<td>$\longrightarrow$</td><td>$%s$</td>' %f.subs(u,g)) html('</tr>') html('<tr>') html('<td>(<span style=\"color: #ff0000;\">diff</span>)</td>') html('<td> $\downarrow$</td><td></td><td></td><td> $\downarrow$</td>') html('</tr>') html('<tr>') html('<td></td><td>') html('<td>$%s$</td><td> $\\times$</td><td></td><td>$%s$</td>' %(g.diff(x),f.diff(u))) html('</tr>') html('<tr>') html('<td></td><td></td><td></td><td> $\downarrow$</td>') html('</tr>') html('<tr>') html('<td>($u=%s$)</td><td></td><td></td>' %g) html('<td>$%s$ $%s$</td>' %(g.diff(x),f.diff(u).subs(u,g))) html('</tr>') html('</tbody>') html('</table>') html('\n========= <span style=\"color: #0000ff;\"><strong> .oo000oo. End .oo000oo. </strong></span> ==========')
ChainRule3(sin(u),x^3,x)
============ Chain Rule =============
The derivative of f(g(x)) = sin(x**3)
with f(u)=sin(u) u=g(x)=x**3 ==>
x**3
sin(u)
x \longrightarrow x**3
\longrightarrowsin(x**3)
(diff)
\downarrow \downarrow
3*x**2 \timescos(u)
\downarrow
(u=x**3)
3*x**2 cos(x**3)
========= .oo000oo. End .oo000oo. ==========