Basic Examples
Step-by-step examples demonstrating the fundamental operations and use cases of iTensor.
Getting Started with Examples
This section provides hands-on examples to help you understand how to use iTensor in practice. Each example includes code snippets, explanations, and expected outputs to guide you through common operations and workflows.
All examples can be run directly using the iTensor API. You can copy the code snippets and execute them using your preferred HTTP client (curl, Postman, Insomnia, or directly in your application).
Example 1: Matrix Addition
This example demonstrates how to add two numerical matrices using the iTensor API.
Request
Response
This example adds two 2×2 matrices element-wise. Each element in the result is the sum of the corresponding elements in matrices A and B.
Example 2: Matrix Multiplication
This example shows how to perform matrix multiplication between two numerical matrices.
Request
Response
This example multiplies a 2×3 matrix with a 3×2 matrix using standard matrix multiplication rules. The resulting matrix has shape [2, 2] where each element is computed as the dot product of a row from matrix A and a column from matrix B.
Example 3: Symbolic Differentiation
This example demonstrates how to compute symbolic derivatives of tensor expressions.
Request
Response
This example computes the partial derivative of a 2×2 tensor with respect to the variable x. Note that only elements containing x are differentiated, while elements without x have derivatives of zero.
Example 4: Creating Special Tensors
This example shows how to create special tensors like identity matrices and tensors filled with zeros.
Creating an Identity Matrix
Response
Creating a Tensor Filled with Zeros
Response
Example 5: Converting Between Symbolic and Numerical
This example demonstrates how to define a tensor symbolically and then evaluate it with numerical values.
Step 1: Create a Symbolic Tensor
Step 2: Evaluate with a Specific Angle
Response
This example demonstrates a common workflow: first defining a tensor symbolically (in this case, a 2D rotation matrix) and then evaluating it with specific numerical values (theta = 0.5 radians).