I was looking at this post since I would like to create an array where each column is one x vector aranged by dx with the corresponding dx, respectively. Hopefully this makes sense.
import numpy as np
L = 80.0
N = 2 ** np.arange(-4, 10, dtype = np.float64)
dx = L / N
With my original code, I was on looking at one dx where now I have an array of dx values.
When I was only using one dx, I set up my x vector up as follows:
x = np.arange(-L / 2., L / 2. - dx, dx)
However, I need an x for each dx but I am not sure on how to do this. I looked at the post I mentioned in the beginning which has provided, I think, some insight. I can't seem to tailor it to my needs though--maybe it isn't even the correct approach.
Maybe I need a for loop?
for i in len(dx):
x[i] = np.arange(-L / 2., L / 2. - dx, dx)
Then I would probably need to nest another for loop to pick one dx for each iteration.
I am not sure what would be the correct approach or most efficient though.
To clarify the confusion, in the one dx situation, I had the following set up:
x = np.arange(-L / 2.0, L / 2.0 - dx, dx)
k = np.hstack((np.arange(0, N / 2.0 - 1.0),
np.arange(-N / 2.0, 0))).T * 2.0 * np.pi / L
k1 = 1j * k
k3 = (1j * k) ** 3
u = 2 * (2 / (np.exp(x + 20.0) + np.exp(-x - 20.0))) ** 2
udata = u
tdata = 0.0
Integration here
I then ran the pseudo spectral method with Runge Kutta 4 integration to numerical determine u of the nonlinear KdV equation. I would like to run the code on different dx values so I can find the error and plot 1/dx vs the error where 1/dx is the on the x-axis.
I hope this helps with what I am trying to accomplish.
Since I want to find the error, would I need the same step size? I know the error will plot in the form of exp(-c * dx) where c is an arbitrary constant. I know this because the pseudo spectral method has error of exp(-c / dx) but I will be plotting against 1 / dx.
arange?np.arange(-2, 2)[..., None] + np.arange(3)[None, ...]dx. You might try to usenp.linspacewhere you can specify the number of elements to use but then this would change yourdx.