#! /usr/bin/env python3 # def sympy_derivative ( ): #*****************************************************************************80 # ## sympy_derivative() uses sympy() to evaluate derivatives. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 01 August 2024 # # Author: # # John Burkardt # print ( '' ) print ( 'sympy_derivative():' ) print ( ' Demonstrate the computation of derivatives.' ) print ( '' ) derivative_humps ( ) derivative_x_exp_xt ( ) # # Terminate. # print ( '' ) print ( 'sympy_derivative():' ) print ( ' Normal end of execution.' ) print ( '' ) return def derivative_humps ( ): #*****************************************************************************80 # ## derivative_humps() differentiates humps(x) # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 01 August 2024 # # Author: # # John Burkardt # from sympy import diff from sympy import symbols print ( '' ) print ( 'derivative_humps():' ) print ( ' Differentiate humps(x).' ) x = symbols ( 'x' ) humps = 100 / ( ( 10 * x - 3 )**2 + 1 ) \ + 100 / ( ( 10 * x - 9 )**2 + 4 ) \ - 6 print ( '' ) print ( ' humps(x) = ', humps ) dhumpsdx = diff ( humps, x ) print ( ' d humps /dx = ', dhumpsdx ) d2humpsdx2 = diff ( humps, x, 2 ) print ( ' d2 humps /dx2 = ', d2humpsdx2 ) return def derivative_x_exp_xt ( ): #*****************************************************************************80 # ## derivative_x_exp_xt() differentiates x exp(xt). # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 01 August 2024 # # Author: # # John Burkardt # from sympy import diff from sympy import exp from sympy import symbols print ( '' ) print ( 'derivative_x_exp_xt():' ) print ( ' Differentiate z(x,t) = x*exp(x*t).' ) x = symbols ( 'x' ) t = symbols ( 't' ) z = x * exp ( x * t ) print ( '' ) print ( ' z(x,t) = ', z ) dzdx = diff ( z, x ) print ( ' dzdx = ', dzdx ) dzdt = diff ( z, t ) print ( ' dzdt = ', dzdt ) dz2dt2 = diff ( z, t, 2 ) print ( ' d2zdt2 = ', dz2dt2 ) dz2dtdx = diff ( z, t, x ) print ( ' d2zdtdx = ', dz2dtdx ) return if ( __name__ == "__main__" ): sympy_derivative ( )