-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import numpy as np | ||
import sympy as sp | ||
|
||
def taylorCoeffs(f,varis,order=None,point=None): | ||
"""Computes the Taylor coefficients of f | ||
f=f(varis) up to order about the point, s.th. | ||
eg. f''[h,h] = f'' h kron h | ||
""" | ||
|
||
n = len(varis) | ||
|
||
#default values for order and expansion point | ||
if order is None: | ||
order = 2 | ||
if point is None: | ||
point = [0]*n | ||
|
||
pointDict = dict(zip(varis,point)) | ||
|
||
#f evaluated at point | ||
f0 = f.subs(pointDict) | ||
|
||
ft = [[f0]] | ||
|
||
fo = [f] | ||
fac = 1. | ||
for o in range(order): | ||
#faculty factor in the expansion | ||
fac = fac*1/(o+1) | ||
fco = [] | ||
#Derivation | ||
for fc in fo: | ||
for var in varis: | ||
fco.append(sp.diff(fc,var)) | ||
|
||
fo = fco | ||
|
||
#Evaluation of current der. at point | ||
f0a = [] | ||
for f0 in fco: | ||
f0 = f0.subs(pointDict) | ||
f0a.append(fac*f0) | ||
ft.append(f0a) | ||
#append a list of the current order derivations | ||
|
||
return ft | ||
|
||
def taylorCoeffs2Matrix(taylC,order=None,parsVals=None): | ||
"""list of taylC is evaluated to np.matrix | ||
1st list dim = state dim. | ||
""" | ||
if order is None: | ||
order = 2 | ||
|
||
matT = [] | ||
for o in range(order+1): | ||
swpl = [] | ||
for tidim in taylC: | ||
swpl.append(tidim[o]) | ||
A = sp.Matrix(swpl); | ||
if parsVals is not None: | ||
A = A.subs(parsVals) | ||
matT.append(np.array(np.array(A), np.float)) | ||
|
||
return matT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,29 @@ | ||
import sympy as sp | ||
import modelMFF as model | ||
reload(model) | ||
import carlem | ||
reload(carlem) | ||
|
||
order = 2; | ||
|
||
tF = [] #taylor coefficients | ||
for fi in model.F: | ||
tF.append(carlem.taylorCoeffs(fi,model.varis)) | ||
|
||
tG = [] | ||
for gk in model.G: | ||
tGk = [] | ||
for gki in gk: | ||
tGk.append(carlem.taylorCoeffs(gki,model.varis)) | ||
tG.append(tGk) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import sympy as sp | ||
#the mean field flow model | ||
|
||
#definition of the variables | ||
a1, a2, a3 = sp.symbols('a1, a2, a3') | ||
varis = [a1, a2, a3] | ||
#definition of the parameters | ||
sigs, oms, bet, gam = sp.symbols('sigs, oms, bet, gam') | ||
params = [sigs, oms, bet, gam] | ||
|
||
#definition of the F-function components | ||
f1 = (sigs-bet*a3)*a1 + (oms + gam*a3)*a2 | ||
f2 = (sigs-bet*a3)*a2 - (oms + gam*a3)*a1 | ||
f3 = (sigs-bet*a3)*a3 + bet*(a1*a1 + a2*a2) | ||
|
||
F = [f1, f2, f3] | ||
|
||
#definition of the k G-functions and its n components | ||
|
||
#all coefficients must be symbols, not ints | ||
g1, g2, g3 = sp.symbols('g1, g2, g3') | ||
g1 = g1.subs(g1,1) | ||
g2 = g2.subs(g2,0) | ||
g3 = g3.subs(g3,0) | ||
|
||
G = [[g1, g2, g3],[g1, g2, g3]]; | ||
|
||
|