- Go - Home
- Go - Overview
- Go - Environment Setup
- Go - Program Structure
- Go - Basic Syntax
- Go - Data Types
- Go - Variables
- Go - Constants
- Go - Identifiers
- Go - Keywords
- Go Operators
- Go - Operators
- Go - Arithmetic Operators
- Go - Assignment Operators
- Go - Relational Operators
- Go - Logical Operators
- Go - Bitwise Operators
- Go - Miscellaneous Operators
- Go - Operators Precedence
- Go Decision Making
- Go - Decision Making
- Go - If Statement
- Go - If Else Statement
- Go - Nested If Statements
- Go - Switch Statement
- Go - Select Statement
- Go Control Flow Statements
- Go - For Loop
- Go - Nested for Loops
- Go - Break Statement
- Go - Continue Statement
- Go - Goto Statement
- Go Functions
- Go - Functions
- Go - Call by Value
- Go - Call by Reference
- Go - Functions as Values
- Go - Function Closure
- Go - Function Method
- Go - Anonymous function
- Go Strings
- Go - Strings
- Go - String Length
- Go - String Concatenation
- Go - Compare Strings
- Go - Split String
- Go - Substring Extraction
- Go - String Replacement
- Go - String Interpolation
- Go - Parse Date Strings
- Go - Pointers
- Go - Pointers
- Go - Array of pointers
- Go - Pointer to pointer
- Go - Passing pointers to functions
- Go Advanced Control Structures
- Go - Scope Rules
- Go - Dereferencing Pointer
- Go - Structures
- Go - Slice
- Go - Slice of Slices
- Go - Range
- Go - Maps
- Go - Recursion
- Go - Type Casting
- Go - Interfaces
- Go - Type Assertion
- Go - Error Handling
- Go - Concurrency
- Go - Regular Expression
- Go - Inheritance
- Go - Packages
- Go - Templates
- Go - Reflection
- Go - Generics
- Go File Handling
- Go - Read File By Word
- Go - Read File By Line
- Go - Read CSV Files
- Go - Delete File
- Go - Rename & Move File
- Go - Truncate a File
- Go - File Read-Write Mode W/O Truncation
- Go Miscellaneous
- Go - defer Keyword
- Go - Fmt Package
- Go - Zero Value
- Go - Import
- Go Useful Resources
- Go - Questions and Answers
- Go - Cheatsheet
- Go - Quick Guide
- Go - Useful Resources
- Go - Discussion
- Go - Online Compilers
Go - Environment Setup
The derivative of a function is its instantaneous rate of change with respect to one of its variables. This is equivalent to finding the slope of the tangent line to the function at a point.we can find the differentiation of mathematical expressions in the form of variables by using diff() function in SymPy package.
diff(expr, variable) >>> from sympy import diff, sin, exp >>> from sympy.abc import x,y >>> expr=x*sin(x*x)+1 >>> expr
The above code snippet gives an output equivalent to the below expression −
$x\sin(x^2) + 1$
>>> diff(expr,x)
The above code snippet gives an output equivalent to the below expression −
$2x^2\cos(x^2) + \sin(x^2)$
>>> diff(exp(x**2),x)
The above code snippet gives an output equivalent to the below expression −
2xex2
To take multiple derivatives, pass the variable as many times as you wish to differentiate, or pass a number after the variable.
>>> diff(x**4,x,3)
The above code snippet gives an output equivalent to the below expression −
$24x$
>>> for i in range(1,4): print (diff(x**4,x,i))
The above code snippet gives the below expression −
4*x**3 12*x**2 24*x
It is also possible to call diff() method of an expression. It works similarly as diff() function.
>>> expr=x*sin(x*x)+1 >>> expr.diff(x)
The above code snippet gives an output equivalent to the below expression −
$2x^2\cos(x^2) + \sin(x^2)$
An unevaluated derivative is created by using the Derivative class. It has the same syntax as diff() function. To evaluate an unevaluated derivative, use the doit method.
>>> from sympy import Derivative >>> d=Derivative(expr) >>> d
The above code snippet gives an output equivalent to the below expression −
$\frac{d}{dx}(x\sin(x^2)+1)$
>>> d.doit()
The above code snippet gives an output equivalent to the below expression −
$2x^2\cos(x^2) + \sin(x^2)$