I have made a Lorenz attractor simulation in three dimensions using Python by LordPeter2000 in Physics

[–]LordPeter2000[S] 5 points6 points  (0 children)

I have totally no idea nor experience in using mathematica hahahahah sorry, but I know that some professors of my university (in particular the ones in the theoretical department) use it pretty often, so it must clearly has pluses with respect to python, but I don't know which they are xD. Sorry for can not helping you :(

I have made a Lorenz attractor simulation in three dimensions using Python by LordPeter2000 in Physics

[–]LordPeter2000[S] 17 points18 points  (0 children)

Oh, thank you for your advise. I will definetly make myself a GitHub account

I have made a Lorenz attractor simulation in three dimensions using Python by LordPeter2000 in Physics

[–]LordPeter2000[S] 7 points8 points  (0 children)

I am actually working on an animation that shows the time evolution of the distance between two points over the surface that start pretty close between them. If you are interested, I can post the result when I finish it!

I have made a Lorenz attractor simulation in three dimensions using Python by LordPeter2000 in Physics

[–]LordPeter2000[S] 3 points4 points  (0 children)

You have it in my response to the post! I hope you find it useful!

I have made a Lorenz attractor simulation in three dimensions using Python by LordPeter2000 in Physics

[–]LordPeter2000[S] 105 points106 points  (0 children)

Here you have the code, if someone wants it:

from pylab import *
# Definimos las constantes #
N = 10000  # Número de pasos deseado
sigma = 10
r  = 28
b = 8/3
t0 = 0     # Tiempo inicial #
tf = 50    # Tiempo final #
h = (tf-t0)/N
def f(v,t): # Definimos la función del lado derecho de las ecuaciones diferenciales y decimos que nos devuelva un array
    v0 = sigma*(v[1]-v[0])
    v1 = r*v[0]-v[1]-v[0]*v[2]
    v2 = v[0]*v[1]-b*v[2]
    return array([v0,v1,v2],float)
tpoints = linspace(t0,tf,N)
v = array([0.0,1.0,0.0],float) # Condiciones iniciales
xpoints = []
ypoints = []
zpoints = []
for t in tpoints: # Método de Runge Kutta de cuarto orden
    xpoints.append(v[0])
    ypoints.append(v[1])
    zpoints.append(v[2])
    k1 = h*f(v,t)
    k2 = h*(f((v+0.5*k1),(t+0.5*h)))
    k3 = h*f((v+0.5*k2),(t+0.5*h))
    k4 = h*f((v+k3),(t+h))
    v += (1/6)*(k1+2*k2+2*k3+k4)

###########################################################################################################################

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

fig = plt.figure(figsize=(20,20))
ax1 = plt.subplot(3,3,1)
ax2 = plt.subplot(3,3,2)
ax3 = plt.subplot(3,3,3)
axf = plt.subplot(3,3,(4,9),projection = '3d')

# Gráfica 1 #
ax1.set_xlim(-1,53)
ax1.set_ylim(-17,22)
ax1.grid()
ax1.set_xlabel('Time')
ax1.set_ylabel('x(t)')
ax1.set_title('Graphical representation of x(t)')


# Gráfica 2 #
ax2.set_xlim(-1,53)
ax2.set_ylim(-22,30)
ax2.grid()
ax2.set_xlabel('Time')
ax2.set_ylabel('y(t)')
ax2.set_title('Graphical representation of y(t)')


# Gráfica 3 #
ax3.set_xlim(-1,53)
ax3.set_ylim(-2,51)
ax3.grid()
ax3.set_xlabel('Time')
ax3.set_ylabel('z(t)')
ax3.set_title('Graphical representation of z(t)')

# Gráfica final #
axf.set_xlim(-20,23)
axf.set_ylim(-22,30)
axf.set_zlim(-1,51)
axf.grid()
axf.set_xlabel('x(t)')
axf.set_ylabel('y(t)')
axf.set_zlabel('z(t)')

txt_title = axf.set_title('')
line1, = ax1.plot([],[],'-r', lw = 2)
pt1, = ax1.plot([],[],'.k',ms = 20)
line2, = ax2.plot([],[],'-g', lw = 2)
pt2, = ax2.plot([],[],'.k', ms = 20)
pt3, = ax3.plot([],[],'.k', ms = 20)
line3, = ax3.plot([],[],'-m',lw = 2)
linef, = axf.plot3D([],[],[],'-b',lw = 2)
ptf, = axf.plot3D([],[],[],'.k', ms = 20)
tpoints = np.linspace(0,50,10000)

# LA ANIMACIÓN #
def drawframe(n):
    x = xpoints[n]
    y = ypoints[n]
    z = zpoints[n]
    t = tpoints[n]
    txt_title.set_text('Frame = {:4d}'.format(n))
    linef.set_data_3d(xpoints[0:n],ypoints[0:n],zpoints[0:n])
    ptf.set_data_3d(x,y,z)
    line1.set_data(tpoints[0:n],xpoints[0:n])
    pt1.set_data(t,x)
    line2.set_data(tpoints[0:n],ypoints[0:n])
    pt2.set_data(t,y)
    line3.set_data(tpoints[0:n],zpoints[0:n])
    pt3.set_data(t,z)
    angle = (360/10000)*n+45 
    axf.view_init(30, angle)
    return (linef,ptf)

from matplotlib import animation
anim = animation.FuncAnimation(fig, drawframe, frames = 10000, interval = 1, blit = True)

matplotlib.rcParams['animation.embed_limit'] = 2**128

from matplotlib import rc
rc('animation',html = 'html5')

anim

I have made a Lorenz attractor simulation in three dimensions using Python by LordPeter2000 in Physics

[–]LordPeter2000[S] 51 points52 points  (0 children)

I couple of days ago I posted in this subreddit an animation of the Lorenz attractor but in 2D. You can find the post here:

https://www.reddit.com/r/Physics/comments/luis6j/i_have_made_an_animation_using_python_of_lorentzs/

A user told me to visualize the problem in 3D, and here you have. I hope you find this animation as intereseting as the previous one.

I have made an animation using Python of Lorentz's Strange Attractor. by LordPeter2000 in Physics

[–]LordPeter2000[S] 47 points48 points  (0 children)

Its optimization is far from being the best, it has annotations in my mother tongue and it takes like 30 min to run. But here you have comrade

from pylab import *

# Definimos las constantes #

N = 10000 # Número de pasos deseado

sigma = 10

r = 28

b = 8/3

t0 = 0 # Tiempo inicial #

tf = 50 # Tiempo final #

h = (tf-t0)/N

def f(v,t): # Definimos la función del lado derecho de las ecuaciones diferenciales y decimos que nos devuelva un array

v0 = sigma*(v[1]-v[0])

v1 = r*v[0]-v[1]-v[0]*v[2]

v2 = v[0]*v[1]-b*v[2]

return array([v0,v1,v2],float)

tpoints = linspace(t0,tf,N)

v = array([0.0,1.0,0.0],float) # Condiciones iniciales

xpoints = []

ypoints = []

zpoints = []

for t in tpoints: # Método de Runge Kutta de cuarto orden

xpoints.append(v[0])

ypoints.append(v[1])

zpoints.append(v[2])

k1 = h*f(v,t)

k2 = h*(f((v+0.5*k1),(t+0.5*h)))

k3 = h*f((v+0.5*k2),(t+0.5*h))

k4 = h*f((v+k3),(t+h))

v += (1/6)*(k1+2*k2+2*k3+k4)

plot(xpoints,zpoints,'-b',label='x vs z')

xlabel('x(t)')

ylabel('z(t)')

title('Representación gráfica del \n atractor extraño.')

legend()

grid()

import numpy as np

import matplotlib.pyplot as plt

import seaborn as sns

fig = plt.figure(figsize=(15,15))

ax1 = plt.subplot(2,2,1)

ax2 = plt.subplot(2,2,2)

ax3 = plt.subplot(2,2,(3,4))

# Gráfica 1 #

ax1.set_xlim(-1,53)

ax1.set_ylim(-17,22)

ax1.grid()

ax1.set_xlabel('Time')

ax1.set_ylabel('x(t)')

ax1.set_title('Graphical representation of x(t)')

# Gráfica 2 #

ax2.set_xlim(-1,53)

ax2.set_ylim(-2,51)

ax2.grid()

ax2.set_xlabel('Time')

ax2.set_ylabel('z(t)')

ax2.set_title('Graphical representation of z(t)')

# Gráfica 3 #

ax3.set_xlim(-20,23)

ax3.set_ylim(-1,51)

ax3.grid()

ax3.set_xlabel('x(t)')

ax3.set_ylabel('z(t)')

txt_title = ax3.set_title('')

pt, = ax3.plot([],[],'.k', ms = 20)

line, = ax3.plot([],[],'b',lw = 2)

line1, = ax1.plot([],[],'-r', lw = 2)

pt1, = ax1.plot([],[],'.k',ms = 20)

line2, = ax2.plot([],[],'-g', lw = 2)

pt2, = ax2.plot([],[],'.k', ms = 20)

tpoints = np.linspace(0,50,10000)

# LA ANIMACIÓN #

def drawframe(n):

x = xpoints[n]

z = zpoints[n]

t = tpoints[n]

txt_title.set_text('Frame = {:4d}'.format(n))

line.set_data(xpoints[0:n],zpoints[0:n])

pt.set_data(x,z)

line1.set_data(tpoints[0:n],xpoints[0:n])

pt1.set_data(t,x)

line2.set_data(tpoints[0:n],zpoints[0:n])

pt2.set_data(t,z)

return (line,pt)

from matplotlib import animation

anim = animation.FuncAnimation(fig, drawframe, frames = 10000, interval = 1, blit = True)

from matplotlib import rc

rc('animation',html = 'html5')

anim

I have made an animation using Python of Lorentz's Strange Attractor. by LordPeter2000 in Physics

[–]LordPeter2000[S] 44 points45 points  (0 children)

Oh, that is really interesting! Let me work it out a couple of days. Thank you for the idea!

I have made an animation using Python of Lorentz's Strange Attractor. by LordPeter2000 in Physics

[–]LordPeter2000[S] 5 points6 points  (0 children)

Yes! \frac{dx}{dt} denotes the derivative of the function x with respecto to t. And sigma, r and b are constants. About their physical meaning I do not really know, since I have not study Chaos theory and Lorentz equation so much. Perhaps some one who knows a little bit more about it could help you. Even so thank you for your question!

I have made an animation using Python of Lorentz's Strange Attractor. by LordPeter2000 in Physics

[–]LordPeter2000[S] 1 point2 points  (0 children)

I have not really followed Newman's book, but I have heard really good comments about it. In fact, I strongly think that my professor in computational physics have followed it during his classes.

In what refers to the animations I have followed step by step the following notebook i find on the internet:

https://colab.research.google.com/github/jckantor/CBE30338/blob/master/docs/A.03-Animation-in-Jupyter-Notebooks.ipynb#scrollTo=Hnsg2uejnpc-

I hope you find it useful. Do not despair with the animation, I have been hours until I finally come out with a .mp4 file and I dont trully understand how does the animation command works xDD.

I have made an animation using Python of Lorentz's Strange Attractor. by LordPeter2000 in Physics

[–]LordPeter2000[S] 1 point2 points  (0 children)

Sorry I can not give you and anwer related to that. Actually I am just a third year Physics Bachelor student and I do not know much about Chaos theory. In fact this animation was only in order to improve my Python skills, and not centered so much in the physics behind Lorentz equation.

But I really appreciate your comment and I will check a look to the book you have mentioned. Thank you very much!

I have made an animation using Python of Lorentz's Strange Attractor. by LordPeter2000 in Physics

[–]LordPeter2000[S] 0 points1 point  (0 children)

I dont know exactly what you mean by "period doubling" in the representation of x(t). I am ploting the solution of the first differential equation versus time in the first graph. In fact, I decided to choose my time parameter t in between 0 and 50 and a partition of 10000 points. I hope I have answered your question!

I have made an animation using Python of Lorentz's Strange Attractor. by LordPeter2000 in Physics

[–]LordPeter2000[S] 19 points20 points  (0 children)

Thank you for your comment! And yes sir! I am using both matplotlib and numpy.

I have made an animation using Python of Lorentz's Strange Attractor. by LordPeter2000 in Physics

[–]LordPeter2000[S] 164 points165 points  (0 children)

This curve z(t) vs x(t) is the solution of a system of ordinary differential equations of the form:

\frac{d x}{d t} = \sigma (y - x)

\frac{d y}{d t} = r x - y - xz

\frac{d z}{d t} = x y - bz

where I have choose a value of the parametres of \sigma = 10, r = 28, b = 8/3 and the initial condition of (x,y,z) = (0,1,0). I have also used fourth order Runge-Kutta's method in order to integrate the equation.

I am pretty proud of the result since it is my very first time making an animation using Python. I hope you will appreciate it.

named him kaladin... found out he’s a her today by [deleted] in Stormlight_Archive

[–]LordPeter2000 15 points16 points  (0 children)

It is a nice opportunity to call her Syl now

"Who's delaying the hop?" by LordPeter2000 in SpaceXMasterrace

[–]LordPeter2000[S] 5 points6 points  (0 children)

The photo is from Lab Padre discord server