In [ ]:
# Code doesn't work

In [1]:
import random
from math import *
import pandas as pd

In [2]:
points = float(256)
modes = float(3)
seed = 5

In [3]:
random.seed(seed)

Пример для трёх гармоник


In [4]:
a_coef = [[random.random(), random.random(), random.random()],
     [random.random(), random.random(), random.random()],
     [random.random(), random.random(), random.random()]]
b_coef =  [[random.random(), random.random(), random.random()],
     [random.random(), random.random(), random.random()],
     [random.random(), random.random(), random.random()]]

In [9]:
def f(a, b, k1, k2, x, y):
    return a*cos(k1*x+k2*y) + b*sin(k1*x+k2*y)
def fx(a, b, k1, k2, x, y):
    return k1*(- a*sin(k1*x+k2*y) + b*cos(k1*x+k2&y) )
def fy(a, b, k1, k2, x, y):
    return k2*(- a*sin(k1*x+k2*y) + b*cos(k1*x+k2&y) )
def fxx(a, b, k1, k2, x, y):
    return k1*k1*(-a*cos(k1*x+k2*y) - b*sin(k1*x+k2&y))
def fyy(a, b, k1, k2, x, y):
    return k2*k2*(-a*cos(k1*x+k2*y) - b*sin(k1*x+k2&y))
def fxy(a, b, k1, k2, x, y):
    return k1*k2*(-a*cos(k1*x+k2*y) - b*sin(k1*x+k2&y))
def fxxx(a, b, k1, k2, x, y):
    return k1*k1*k1*(a*sin(k1*x+k2*y) - b*cos(k1*x+k2&y))
def fyyy(a, b, k1, k2, x, y):
    return k2*k2*k2*(a*sin(k1*x+k2*y) - b*cos(k1*x+k2&y))
def fxyy(a, b, k1, k2, x, y):
    return k1*k2*k2*(a*sin(k1*x+k2*y) - b*cos(k1*x+k2&y))
def fyxx(a, b, k1, k2, x, y):
    return k1*k1*k2*(a*sin(k1*x+k2*y) - b*cos(k1*x+k2&y))

In [ ]:
d = pd.DataFrame()
for j1 in range(0, int(points-1)):
    for j2 in range (0, int(points-1)):
        fx_ = 0.0
        x = j1/(points-1)
        y = j2/(points-1)
        for k1 in range (0, int(modes)-1):
            for k2 in range (0, int(modes)-1):
                fx_ = fx_ + f(a_coef[k1][k2], b_coef[k1][k2], k1, k2, x, y)
                d = d.append([x, y, fx_])

In [ ]:
np.savetxt("foo.dat", d, delimiter="    ")