{{ message }}

Instantly share code, notes, and snippets.

# surt91/plot.py

Created Sep 16, 2016
Solving and plotting the Lorenz Attractor
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
 #!/usr/bin/env python3 import matplotlib as mpl from mpl_toolkits.mplot3d import Axes3D import numpy as np import matplotlib.pyplot as plt if __name__ == "__main__": with open("lorenz.txt","r",encoding='utf-8') as f: tmp=[i.split(" ") for i in f.readlines()] x=[float(i[0]) for i in tmp] y=[float(i[1]) for i in tmp] z=[float(i[2]) for i in tmp] xs=np.array(x) ys=np.array(y) zs=np.array(z) fig = plt.figure() ax = fig.gca(projection='3d') ax.plot(xs, ys, zs) plt.savefig("lorenz.png", format="png")
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
 #include "runge_kutta.h" double * rk4(double *z0, double tau, double * (*dgl)(), double T, int dim) { double *zout, *z_seq, t; int j, n, N; N = T/tau; z_seq = (double *) calloc(dim * N, sizeof(double)); zout = (double *) calloc(dim, sizeof(double)); for(j=0;j
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
 #ifndef RUNGE_KUTTA_H #define RUNGE_KUTTA_H #include #include double * rk4_step(double *z, double t, double tau, double * (*dgl)(), int dim); double * H(double *z, double t, int dim); double * rk_lorenz_func(double *r, double t, int dim); #endif //RUNGE_KUTTA_H