### TL: added sympy example, typo

parent 4b85e599
 ... ... @@ -25,5 +25,9 @@ Contains scripts that use numpy python package for specific applications Contains scripts that use scipy python package for specific applications ## [sympy](sympy/) Contains scripts that use sympy python package for symbolic computation [MarkDown documentation](https://docs.gitlab.com/ee/user/markdown.html) - General synthax for *.md* files
 ... ... @@ -12,8 +12,9 @@ in the [data.txt](data.txt) file, modify those and write the modified data into ## [callFortranRoutine.py](callFortranRoutine.py) Perform the [Rutishauser-Kahan-Pal-Walker algorithm](https://link.springer.com/content/pdf/10.1007/BF01405565.pdf) to transform an arrow matrix (with non-zero elements in the first row and column, and diagonal) into a symmetric trifdiagonal matrix. It uses the [f2py](https://www.numfys.net/howto/F2PY/) sub-module of numpy to compile a fortran subroutine that can be called in python. in the first row and column, and diagonal) into a symmetric tridiagonal matrix. It uses the [f2py](https://www.numfys.net/howto/F2PY/) sub-module of numpy to compile a fortran subroutine (written in [libfor.f95](libfor.f95)) that can be called in python. ## [csv-read-interpol-plot.py](csv-read-interpol-plot.py) ... ...
 ... ... @@ -7,4 +7,9 @@ Also, you can look at an [extended list of Sympy Tutorials](http://docs.sympy.or This script is a basic example of how to solve a differential equation using sympy. In particular, the equation u''(t) - u(t) = exp(t) is solved, using the sympy function dsolve [minimize](http://docs.sympy.org/latest/modules/solvers/ode.html). 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). ## [generalMidPointInterpolation.py](generalMidPointInterpolation.py) This script compute the general formula of mid-point interpolation on one-dimensionnal uniform grids. The interpolation can be computed for any order (1, 3, 5, ... always an odd number)
 #!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Wed Oct 19 18:54:50 2016 @author: t.lunet """ import sympy as sy from time import time sy.init_printing() # Interpolation order : 1, 3, 5, ... always odd number nP = 1 # Setup computations i0 = (nP-1)//2 A = sy.zeros(nP+1) e = sy.ones(1, nP+1) # Construction of dX symbols lDx = [] for i in range(nP): lDx.append(sy.Symbol('\\Delta x_{'+str(i-i0)+'}')) lPos = *(nP+1) lPos[i0] = 0 for i in range((nP-1)//2): lPos[i0-i-1] = lPos[i0-i]-lDx[i0-i-1] for i in range((nP+1)//2): lPos[i0+i+1] = lPos[i0+i]+lDx[i0+i] # Contruct vandermonde matrix for i in range(nP+1): c = i-i0 for j in range(nP+1): A[i, j] = c**j # Coordinate for middle point for i in range(nP+1): e[0, i] /= 2**i print('Inverting A') t0 = time() coeff = e * A.inv() print(' -- computation time = {:.2f}'.format(time()-t0)) print('Simplifying coeff') t0 = time() coeff.simplify() print(' -- computation time = {:.2f}'.format(time()-t0))
 #!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Sympy example: How to solve a differential equation using sympy Sympy example: How to solve a differential equation using sympy @author: a.perez """ import sympy as sy sy.init_printing() # Define a generic function u and its variable, t u = sy.Function('u') ... ... @@ -25,7 +26,7 @@ eq = sy.Eq(lhs, rhs) # We create the equation sol = sy.dsolve(eq, u(t)) # And we solve it using the function dsolve, # wrt the function u(t) # Now sol is the equation: # u(t) = C2*exp(-t) + (C1 + t/2)*exp(t)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!