lyapunov spectrum of lorenz oscillator












0














Here is my try to calculate lyapunov spectrum of lorenz oscillator. I followed step by step from boost library program, but I can not reproduce the results.



import numpy as np
import pylab as pl
from copy import copy
from numpy import dot, log
from numpy.linalg import norm
from scipy.integrate import odeint
from sys import exit


# system with out perturbation----------------------------#
def lorenz(x0, t):
x, y, z = x0
dxdt = s * (y - x)
dydt = x * (r - z) - y
dzdt = x * y - b * z
return [dxdt, dydt, dzdt]

#system with perturbation---------------------------------#
def lorenz_with_lyap(x0, t):
x,y,z = x0[:3]
dxdt = [0.0]*12

dxdt[0] = s * (y - x)
dxdt[1] = x * (r - z) - y
dxdt[2] = x * y - b * z

# this is jacobian*Y
for l in range(3):
m = 3*l+3
dxdt[m] = -s * x0[m] + s * x0[m+1]
dxdt[m+1] = (r - z) * x0[m] -1.0 * x0[m+1] -1.0 * x * x0[m+2]
dxdt[m+2] = y * x0[m] + x * x0[m+1] -b * x0[m+2]
return dxdt
#---------------------------------------------------------#
def gram_schmidt(x0, lyap, t):
# vectors
a = x0[3: 6]
b = x0[6: 9]
c = x0[9:12]

v1 = copy(a)
v2 = b - dot(v1, b)/dot(v1, v1) * v1
v3 = c - dot(v1, c)/dot(v1, v1) * v1 -dot(v2, c)/dot(v2, v2) * v2

znorm = [0] * 3
znorm[0] = norm(v1)
znorm[1] = norm(v2)
znorm[2] = norm(v3)

# normalize vectors
x0[3:6 ] = v1/znorm[0]
x0[6:9 ] = v2/znorm[1]
x0[9:12] = v3/znorm[2]


for i in range(3):
lyap[i] += log(znorm[i])/t



# parameters
s = 10.0
r = 28.0
b = 8.0/3.0
stept = 1.0
dt = 0.01
n = 3
lyap = [0.0]*n

x0 = np.zeros(12)
initial_condition = [10.0, 10.0, 5.0]
x0[:3] = copy(initial_condition)

for i in range(3):
x0[n+n*i+i]=1.0


# integrate trantient time
t = np.arange(0, 10, 0.1)
sol = odeint(lorenz, initial_condition, t)
x0[:3] = copy(sol[-1,:]) # new initial condition

ti = t[-1]
tf = ti + stept

for i in range(10):

t_interval = np.arange(ti, tf, dt)
sol = odeint(lorenz_with_lyap, x0, t_interval)

x0 = copy(sol[-1,:])

gram_schmidt(x0, lyap, stept)

for xx in lyap:
print "%15.9f" % xx,
print ""

ti = tf
tf = ti+stept


I think the problem is in gram_schmidt function. Is the question clear?
Thank you for any guide.









share



























    0














    Here is my try to calculate lyapunov spectrum of lorenz oscillator. I followed step by step from boost library program, but I can not reproduce the results.



    import numpy as np
    import pylab as pl
    from copy import copy
    from numpy import dot, log
    from numpy.linalg import norm
    from scipy.integrate import odeint
    from sys import exit


    # system with out perturbation----------------------------#
    def lorenz(x0, t):
    x, y, z = x0
    dxdt = s * (y - x)
    dydt = x * (r - z) - y
    dzdt = x * y - b * z
    return [dxdt, dydt, dzdt]

    #system with perturbation---------------------------------#
    def lorenz_with_lyap(x0, t):
    x,y,z = x0[:3]
    dxdt = [0.0]*12

    dxdt[0] = s * (y - x)
    dxdt[1] = x * (r - z) - y
    dxdt[2] = x * y - b * z

    # this is jacobian*Y
    for l in range(3):
    m = 3*l+3
    dxdt[m] = -s * x0[m] + s * x0[m+1]
    dxdt[m+1] = (r - z) * x0[m] -1.0 * x0[m+1] -1.0 * x * x0[m+2]
    dxdt[m+2] = y * x0[m] + x * x0[m+1] -b * x0[m+2]
    return dxdt
    #---------------------------------------------------------#
    def gram_schmidt(x0, lyap, t):
    # vectors
    a = x0[3: 6]
    b = x0[6: 9]
    c = x0[9:12]

    v1 = copy(a)
    v2 = b - dot(v1, b)/dot(v1, v1) * v1
    v3 = c - dot(v1, c)/dot(v1, v1) * v1 -dot(v2, c)/dot(v2, v2) * v2

    znorm = [0] * 3
    znorm[0] = norm(v1)
    znorm[1] = norm(v2)
    znorm[2] = norm(v3)

    # normalize vectors
    x0[3:6 ] = v1/znorm[0]
    x0[6:9 ] = v2/znorm[1]
    x0[9:12] = v3/znorm[2]


    for i in range(3):
    lyap[i] += log(znorm[i])/t



    # parameters
    s = 10.0
    r = 28.0
    b = 8.0/3.0
    stept = 1.0
    dt = 0.01
    n = 3
    lyap = [0.0]*n

    x0 = np.zeros(12)
    initial_condition = [10.0, 10.0, 5.0]
    x0[:3] = copy(initial_condition)

    for i in range(3):
    x0[n+n*i+i]=1.0


    # integrate trantient time
    t = np.arange(0, 10, 0.1)
    sol = odeint(lorenz, initial_condition, t)
    x0[:3] = copy(sol[-1,:]) # new initial condition

    ti = t[-1]
    tf = ti + stept

    for i in range(10):

    t_interval = np.arange(ti, tf, dt)
    sol = odeint(lorenz_with_lyap, x0, t_interval)

    x0 = copy(sol[-1,:])

    gram_schmidt(x0, lyap, stept)

    for xx in lyap:
    print "%15.9f" % xx,
    print ""

    ti = tf
    tf = ti+stept


    I think the problem is in gram_schmidt function. Is the question clear?
    Thank you for any guide.









    share

























      0












      0








      0







      Here is my try to calculate lyapunov spectrum of lorenz oscillator. I followed step by step from boost library program, but I can not reproduce the results.



      import numpy as np
      import pylab as pl
      from copy import copy
      from numpy import dot, log
      from numpy.linalg import norm
      from scipy.integrate import odeint
      from sys import exit


      # system with out perturbation----------------------------#
      def lorenz(x0, t):
      x, y, z = x0
      dxdt = s * (y - x)
      dydt = x * (r - z) - y
      dzdt = x * y - b * z
      return [dxdt, dydt, dzdt]

      #system with perturbation---------------------------------#
      def lorenz_with_lyap(x0, t):
      x,y,z = x0[:3]
      dxdt = [0.0]*12

      dxdt[0] = s * (y - x)
      dxdt[1] = x * (r - z) - y
      dxdt[2] = x * y - b * z

      # this is jacobian*Y
      for l in range(3):
      m = 3*l+3
      dxdt[m] = -s * x0[m] + s * x0[m+1]
      dxdt[m+1] = (r - z) * x0[m] -1.0 * x0[m+1] -1.0 * x * x0[m+2]
      dxdt[m+2] = y * x0[m] + x * x0[m+1] -b * x0[m+2]
      return dxdt
      #---------------------------------------------------------#
      def gram_schmidt(x0, lyap, t):
      # vectors
      a = x0[3: 6]
      b = x0[6: 9]
      c = x0[9:12]

      v1 = copy(a)
      v2 = b - dot(v1, b)/dot(v1, v1) * v1
      v3 = c - dot(v1, c)/dot(v1, v1) * v1 -dot(v2, c)/dot(v2, v2) * v2

      znorm = [0] * 3
      znorm[0] = norm(v1)
      znorm[1] = norm(v2)
      znorm[2] = norm(v3)

      # normalize vectors
      x0[3:6 ] = v1/znorm[0]
      x0[6:9 ] = v2/znorm[1]
      x0[9:12] = v3/znorm[2]


      for i in range(3):
      lyap[i] += log(znorm[i])/t



      # parameters
      s = 10.0
      r = 28.0
      b = 8.0/3.0
      stept = 1.0
      dt = 0.01
      n = 3
      lyap = [0.0]*n

      x0 = np.zeros(12)
      initial_condition = [10.0, 10.0, 5.0]
      x0[:3] = copy(initial_condition)

      for i in range(3):
      x0[n+n*i+i]=1.0


      # integrate trantient time
      t = np.arange(0, 10, 0.1)
      sol = odeint(lorenz, initial_condition, t)
      x0[:3] = copy(sol[-1,:]) # new initial condition

      ti = t[-1]
      tf = ti + stept

      for i in range(10):

      t_interval = np.arange(ti, tf, dt)
      sol = odeint(lorenz_with_lyap, x0, t_interval)

      x0 = copy(sol[-1,:])

      gram_schmidt(x0, lyap, stept)

      for xx in lyap:
      print "%15.9f" % xx,
      print ""

      ti = tf
      tf = ti+stept


      I think the problem is in gram_schmidt function. Is the question clear?
      Thank you for any guide.









      share













      Here is my try to calculate lyapunov spectrum of lorenz oscillator. I followed step by step from boost library program, but I can not reproduce the results.



      import numpy as np
      import pylab as pl
      from copy import copy
      from numpy import dot, log
      from numpy.linalg import norm
      from scipy.integrate import odeint
      from sys import exit


      # system with out perturbation----------------------------#
      def lorenz(x0, t):
      x, y, z = x0
      dxdt = s * (y - x)
      dydt = x * (r - z) - y
      dzdt = x * y - b * z
      return [dxdt, dydt, dzdt]

      #system with perturbation---------------------------------#
      def lorenz_with_lyap(x0, t):
      x,y,z = x0[:3]
      dxdt = [0.0]*12

      dxdt[0] = s * (y - x)
      dxdt[1] = x * (r - z) - y
      dxdt[2] = x * y - b * z

      # this is jacobian*Y
      for l in range(3):
      m = 3*l+3
      dxdt[m] = -s * x0[m] + s * x0[m+1]
      dxdt[m+1] = (r - z) * x0[m] -1.0 * x0[m+1] -1.0 * x * x0[m+2]
      dxdt[m+2] = y * x0[m] + x * x0[m+1] -b * x0[m+2]
      return dxdt
      #---------------------------------------------------------#
      def gram_schmidt(x0, lyap, t):
      # vectors
      a = x0[3: 6]
      b = x0[6: 9]
      c = x0[9:12]

      v1 = copy(a)
      v2 = b - dot(v1, b)/dot(v1, v1) * v1
      v3 = c - dot(v1, c)/dot(v1, v1) * v1 -dot(v2, c)/dot(v2, v2) * v2

      znorm = [0] * 3
      znorm[0] = norm(v1)
      znorm[1] = norm(v2)
      znorm[2] = norm(v3)

      # normalize vectors
      x0[3:6 ] = v1/znorm[0]
      x0[6:9 ] = v2/znorm[1]
      x0[9:12] = v3/znorm[2]


      for i in range(3):
      lyap[i] += log(znorm[i])/t



      # parameters
      s = 10.0
      r = 28.0
      b = 8.0/3.0
      stept = 1.0
      dt = 0.01
      n = 3
      lyap = [0.0]*n

      x0 = np.zeros(12)
      initial_condition = [10.0, 10.0, 5.0]
      x0[:3] = copy(initial_condition)

      for i in range(3):
      x0[n+n*i+i]=1.0


      # integrate trantient time
      t = np.arange(0, 10, 0.1)
      sol = odeint(lorenz, initial_condition, t)
      x0[:3] = copy(sol[-1,:]) # new initial condition

      ti = t[-1]
      tf = ti + stept

      for i in range(10):

      t_interval = np.arange(ti, tf, dt)
      sol = odeint(lorenz_with_lyap, x0, t_interval)

      x0 = copy(sol[-1,:])

      gram_schmidt(x0, lyap, stept)

      for xx in lyap:
      print "%15.9f" % xx,
      print ""

      ti = tf
      tf = ti+stept


      I think the problem is in gram_schmidt function. Is the question clear?
      Thank you for any guide.







      python c++





      share












      share










      share



      share










      asked 5 mins ago









      Abolfazl

      285




      285



























          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210158%2flyapunov-spectrum-of-lorenz-oscillator%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210158%2flyapunov-spectrum-of-lorenz-oscillator%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'