Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

501
Visualizações
How to simulate a wave equation

I've been recently trying to simulate a wave equation in p5.js.

My aproach is to plot a bunch of points with (x, y) coordinates. I've used the wave equation for obtaining the movement of those particles.

This is my numerical integration method:

var pos     = this.masses[i].pos
var nextPos = this.masses[i + 1].pos
var lastPos = this.masses[i - 1].pos

var vel = this.masses[i].vel, acc = this.masses[i].acc // for simplicity

acc.x = 0
acc.y = c * c * ((nextPos.y - 2*pos.y + lastPos.y)) / d2x

vel.x += acc.x * dt
vel.y += acc.y * dt

pos.x += vel.x * dt
pos.y += vel.y * dt

My acceleration is defined as the second derivative with respect to x times the speed of the wave squared, as shown here.

So I convert my equation from this:

(d²u/dt²) = c² (d²u/dx²)

Into a discrete equation like this (where u, represents the position of one particle and c the propagation speed of the waves):

d2u = u(x + 2h, t) - 2*u(x + h, t) + u(x, t)
d2t = 1e-5 // small step
acc = c * c * (d2u / d2t)

But my result is quite strange: my wave

As you can see, the wave grows, when the expected result was something like this:

expected wave

What I'm doing wrong? Someone could help me? Thanks :)

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda