Lattice of harmonic oscillators - Matlab

In summary, the conversation discusses a code that generates a lattice of harmonic oscillators. The algorithm involves nested for loops, but the calculations inside the second loop are the same for each iteration, causing the oscillators to collectively oscillate instead of individually. The use of x(i+1, n) and x(i+2, n) before they are calculated is also noted as a potential issue. The person is seeking help to correct the dynamical equations and understand why the oscillators behave strangely.
  • #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.
 
Physics news on Phys.org
  • #2
All the calculations inside the second for loop are the same for each i value. That's why they oscillate collectively. Another strange thing is that you use x(i+1, n) and x(i+2, n) before they are even calculated. Is the x matrix preloaded with values?
 

1. What is a lattice of harmonic oscillators?

A lattice of harmonic oscillators is a model used in physics to study the behavior of a system of particles that are connected by a series of springs. The particles are able to oscillate back and forth, similar to a mass-spring system, and the interactions between them are described by the laws of harmonic motion.

2. How is Matlab used to simulate a lattice of harmonic oscillators?

Matlab is a programming software that is commonly used by scientists to simulate physical systems. To simulate a lattice of harmonic oscillators in Matlab, one would need to define the properties of the system, such as the mass and spring constants, and then use the appropriate equations to calculate the positions and velocities of the particles at each time step.

3. What are the applications of studying a lattice of harmonic oscillators?

Studying a lattice of harmonic oscillators can provide insights into the behavior of materials such as crystals, which can be modeled as a lattice of particles connected by bonds. It can also be used to understand the properties of solids, such as thermal conductivity and electrical conductivity, as well as for studying the dynamics of molecular systems.

4. What are the limitations of using a lattice of harmonic oscillators model?

While a lattice of harmonic oscillators can provide valuable insights, it is a simplified model and does not account for all factors that may affect the behavior of a system. For example, it assumes that the particles are arranged in a regular lattice, and neglects factors such as external forces and non-harmonic interactions between particles.

5. Can Matlab be used to analyze experimental data from a lattice of harmonic oscillators?

Yes, Matlab can be used to analyze experimental data from a lattice of harmonic oscillators. Scientists can use the software to plot and compare their experimental data with the simulated results from the model, allowing them to validate their findings and make further predictions about the behavior of the system.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
5K
Replies
6
Views
352
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
744
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
Back
Top