diff --git a/examples/sympy/README.md b/examples/sympy/README.md index 57693635d45c6fd7dbdfdbe7c9ae5dc9a09d4418..7590f643b6a7e99429d112b8351f6c517787f3c6 100644 --- a/examples/sympy/README.md +++ b/examples/sympy/README.md @@ -9,6 +9,10 @@ This script is a basic example of how to solve a differential equation using sym In particular, the equation u''(t) - u(t) = exp(t) is solved, using the sympy function [dsolve](http://docs.sympy.org/latest/modules/solvers/ode.html). +## [blockMatrixComputation.py](blockMatrixComputation.py) + +Performs block matrix computation with non-comuutative blocks, and print latex output for the results + ## [generalMidPointInterpolation.py](generalMidPointInterpolation.py) This script compute the general formula of mid-point interpolation on one-dimensionnal uniform grids. diff --git a/examples/sympy/blockMatrixComp.py b/examples/sympy/blockMatrixComp.py new file mode 100644 index 0000000000000000000000000000000000000000..20353705cdf00d29f8959be24a61d672545bdec2 --- /dev/null +++ b/examples/sympy/blockMatrixComp.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +""" +Performs block matrix computations, and print latex formula +""" +import sympy as sy +sy.init_printing() + +# Define symbolds +A, B, C = sy.symbols('A, B, C', commutative=False) +D = sy.symbols('D', commutative=True) + +M = sy.Matrix([[D, B, 0], + [C, D, 0], + [0, 0, A]]) + +# Compute symbolic operations +M1 = M**2 +M1.simplify() + +M2 = (M-sy.eye(3))*M +M2.simplify() + +# Print latex formula +print('M1 = ') +print(sy.latex(M1)) +print('M2 = ') +print(sy.latex(M2)) diff --git a/examples/sympy/generalMidPointInterpolation.py b/examples/sympy/generalMidPointInterpolation.py index 1df28fecbf6c91e68741970561c7c8fa574dbbe2..cc325cc260a6e6cf56afe671568c8ecfa24c33e7 100644 --- a/examples/sympy/generalMidPointInterpolation.py +++ b/examples/sympy/generalMidPointInterpolation.py @@ -1,9 +1,8 @@ #!/usr/bin/env python2 # -*- coding: utf-8 -*- """ -Created on Wed Oct 19 18:54:50 2016 - -@author: t.lunet +Compute the analytical mid-point interpolation formula, for any order, +on uniform 1D grids """ import sympy as sy from time import time