- #1
barnflakes
- 156
- 4
Can someone help me with my code? I am trying to generate a lattice of harmonic oscillators, and I have written the following algorithm:
for n = 2:((N-1)/h)
a(1,n) = -(x0-(x(2,n)-x(1,n)));
x(1,n+1) = 2*x(1,n) -x(1,n-1) + (h^2)*a(1,n);
t(1,n+1) = t(1,n) + (h);
for i = 1:(osc_num-2);
a(i+1,n) = -(2*x(i+1,n) - x(i,n) -x(i+2,n));
x(i+1,n+1) = 2*x(i+1,n) -x(i+1,n-1) + (h^2)*a(i+1,n);
t(i+1,n+1) = t(i+1,n) + (h);
end
end
To generate this, are the dynamical equations correct? There should just be small vibrations of each oscillator around its starting position, but instead they oscillate collectively which is very bizarre. Any help much appreciated.
for n = 2:((N-1)/h)
a(1,n) = -(x0-(x(2,n)-x(1,n)));
x(1,n+1) = 2*x(1,n) -x(1,n-1) + (h^2)*a(1,n);
t(1,n+1) = t(1,n) + (h);
for i = 1:(osc_num-2);
a(i+1,n) = -(2*x(i+1,n) - x(i,n) -x(i+2,n));
x(i+1,n+1) = 2*x(i+1,n) -x(i+1,n-1) + (h^2)*a(i+1,n);
t(i+1,n+1) = t(i+1,n) + (h);
end
end
To generate this, are the dynamical equations correct? There should just be small vibrations of each oscillator around its starting position, but instead they oscillate collectively which is very bizarre. Any help much appreciated.