0

I am trying to work on the 4 dimensional chaotic attractor Lyapunov spectrum and there values so far the code mention below works well for three dimensional system but errors arise in 4D and 5D system

import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import odeint

def diff_Lorenz(u):
    x,y,z,w= u
    f = [a*(y-x) , x*z+w, b-x*y, z*y-c*w]
    Df = [[-a,a,0,0], [z,0, x,1], [-y, -x, 0,0],[0,z,y,-c]]
    return np.array(f), np.array(Df)


def LEC_system(u):
    #x,y,z = u[:3]
    U = u[2:18].reshape([4,4])
    L = u[12:15]
    f,Df = diff_Lorenz(u[:4])
    A = U.T.dot(Df.dot(U))
    dL = np.diag(A).copy();
    for i in range(4):
        A[i,i] = 0
        for j in range(i+1,4): A[i,j] = -A[j,i]
    dU = U.dot(A)
    return np.concatenate([f,dU.flatten(),dL])


a=6;b=11;c=5;

u0 = np.ones(4)
U0 = np.identity(4)
L0 = np.zeros(4)
u0 = np.concatenate([u0, U0.flatten(), L0])
t = np.linspace(0,10,301)
u = odeint(lambda u,t:LEC_system(u),u0,t, hmax=0.05)
L = u[5:,12:15].T/t[5:]

# plt.plot(t[5:],L.T) 
# plt.show()
p1=L[0,:];p2=L[1,:];p3=L[2,:];p4=L[3,:]
L1 = np.mean(L[0,:]);L2=np.average(L[1,:]);L3=np.average(L[2,:]);L4=np.average(L[3,:])
t1 = np.linspace(0,100,len(p1))
plt.plot(t1,p1);plt.plot(t1,p2);plt.plot(t1,p3);plt.plot(t1,p4)

# plt.show()
print('LES= ',L1,L2,L3,L4)

the output error is

D:\anaconda3\lib\site-packages\scipy\integrate\odepack.py:247: ODEintWarning: Excess work done on this call (perhaps wrong Dfun type). Run with full_output = 1 to get quantitative information.
  warnings.warn(warning_msg, ODEintWarning)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_7008/1971199288.py in <module>
     32 # plt.plot(t[5:],L.T)
     33 # plt.show()
---> 34 p1=L[0,:];p2=L[1,:];p3=L[2,:];p4=L[3,:]
     35 L1=np.mean(L[0,:]);L2=np.average(L[1,:]);L3=np.average(L[2,:]);L4=np.average(L[3,:])
     36 t1 = np.linspace(0,100,len(p1))

IndexError: index 3 is out of bounds for axis 0 with size 3

what is wrong?

output expected is L1=.5162,L2=-.0001,L3=-4.9208,L4=-6.5954

Zewo
  • 153
  • 1
  • 12

1 Answers1

1

In LEC_system(u), the flat vector u contains in sequence

  • the state vector, n components,
  • the eigenbasis U, a n x n matrix
  • the accumulated exponents L, n components.

With n=4, this translates thus to the decomposition

def LEC_system(u):
    #x,y,z,w = u[:4]
    U = u[4:20].reshape([4,4])
    L = u[20:24]
    f,Df = diff_Lorenz(u[:4])
    A = U.T.dot(Df.dot(U))
    dL = np.diag(A).copy();
    for i in range(4):
        A[i,i] = 0
        for j in range(i+1,4): A[i,j] = -A[j,i]
    dU = U.dot(A)
    return np.concatenate([f,dU.flatten(),dL])

Of course, in the evaluation after the integration one has to likewise use the correct segment of the state vector

L = u[5:,20:24].T/t[5:]

Then I get the plot enter image description here

and only using the latter quart of the graphs, after integrating to t=60

LES=  0.029214865425355396 -0.43816854013111833 -4.309199339754925 -6.28183676249535

This still are not the expected values, as that appears to be contracting along all directions transversal to the solution curve.

Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51
  • waooo.. plz explain U = u[4:20].reshape([4,4]) L = u[20:24] – Zewo Nov 25 '21 at 19:21
  • The `u` vector is split at (before) the positions `0, n, n+n*n, n+n*n+n`, the outer positions are not splits. For `n=4` the values `0, 4, 20, 24` result. – Lutz Lehmann Nov 25 '21 at 19:24
  • what if the system has 5D then ... 0 , n, n+n*n , n+n*n+n, then ? – Zewo Nov 25 '21 at 19:28
  • Yes, the pattern remains the same, then with the component separations before index `0, 5, 30, 35`. – Lutz Lehmann Nov 25 '21 at 19:31
  • what about this? U = u[4:20] how u get this solved? – Zewo Nov 25 '21 at 19:32
  • for 5D this willbe like this............. U = u[5:30].reshape([5,5]) L = u[30:35]?? – Zewo Nov 25 '21 at 19:33
  • Yes, exactly. The sub-array needs to be reformatted into a matrix. – Lutz Lehmann Nov 25 '21 at 19:35
  • thanks alot ..plz also help me in drawing basin of attractions for different dynamical systems.. if u say ill post a full question for this new query as well.. – Zewo Nov 25 '21 at 19:37
  • Basins of attraction or Fatou sets only work if you have multiple stable fixed/stationary/equilibrium points. Limit cycles or strange attractors work too, but the multiplicity of them is crucial, else you get no differentiation. Another visualization of dynamical systems is the Poincaré section. So if you ask a new question on that, find a sensible example and explain what you expect to see. If it is not a coding problem, the question will likely off-topic here, math.SE or scicomp.SE could be more appropriate. – Lutz Lehmann Nov 25 '21 at 20:23
  • u = odeint(lambda u,t:LEC_system(u),u0,t, hmax=0.05) File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\integrate\odepack.py", line 241, in odeint output = _odepack.odeint(func, y0, t, args, Dfun, col_deriv, ml, mu, TypeError: Cannot cast array data from dtype('O') to dtype('float64') according to the rule 'safe' – Zewo Nov 25 '21 at 20:25
  • for 5 by 5 matrix its giving me this error – Zewo Nov 25 '21 at 20:26
  • given: f = [ y - x + y*z + u + a ,-y + 3*x*z + b,-3*x*y + w,- x + d,-2*x - c*y] Df = [[-1,1+z,y,0,1], [3*z,-1,3*x,0,0], [-3*y,-3*x,0,1,0],[-1,0,0,0,0],[-2,-c,0,0,0]] where; a = 0;b = 1; c = 2; d = -0.01 – Zewo Nov 25 '21 at 20:29
  • Do a search for this error "TypeError ..." for similar cases, it happens often enough. You are passing a structured object, like an array, where a scalar is expected. I can not see from the provided code where this happens – Lutz Lehmann Nov 26 '21 at 06:50
  • Lehmann I posted the new code above as an answer. See there what is the problem! – Zewo Nov 26 '21 at 08:35
  • Please do not do that, open a new question for a new problem, while performing all the usual debugging required. One elementary step is to try the code from a fresh workspace (refresh kernel, or copy into empty), or run the script from the command line. Then you would get the different error "name 'a' is not defined", or in your case, it was defined with some unrelated content, at least in the case of `d`. – Lutz Lehmann Nov 26 '21 at 08:42
  • The fifth scalar variable is `t`, `u` is still the array of all components. – Lutz Lehmann Nov 26 '21 at 08:50
  • changes have made .. still the type error persist .. i think i need to post this question again – Zewo Nov 26 '21 at 09:58
  • 1
    Did you remove the `u` from the first component of `f`? – Lutz Lehmann Nov 26 '21 at 10:01
  • myy baaadddd.............. its working :D thanks aloooot – Zewo Nov 26 '21 at 10:24