Numeric Solution to the wave equation [plus I need some help]
Posted: Sun Jul 02, 2017 1:23 pm
Hey guys!
I wanted to try solving differential equations numerically, and what's better for that task than the wave equation?
Click and drag to create a gauß bell with variable width.
However, I have a problem: As soon as the wave hits the boundary, or as soon as I change a single pixel's value(as opposed to changing a pair's value), the simulation does weird things: It only affects every second bin. Say, we have the array 50,50,50,50,50 and I change a value to 50,50,60,50,50, it becomes 55, 50, 55, 50, 55. And. I. Don't. Know. Why.
All derivatives are just the slope in that particular point, using central differences, and the integration just goes by adding the derivative times dt.... Which is fine, since I wanted a numeric approach. However, I can't get behind the weird bin thing. Anyone got ideas on how to fix it?
On a second approach, I tried to build it from scratch using real bins this time instead of relying on pixels, and here you can see the problem of every second bin not being affected more clearly.
If anyone's curious about my motivation, I want to do two things: write a program that can simulate fluids with different methods (including more than just surface waves) and simulating simple quantum mechanical problems by solving the schrödinger equation numerically.
So, yeah. Any ideas on why it won't work would be appreciated. Have a nice day everyone!
I wanted to try solving differential equations numerically, and what's better for that task than the wave equation?
Click and drag to create a gauß bell with variable width.
However, I have a problem: As soon as the wave hits the boundary, or as soon as I change a single pixel's value(as opposed to changing a pair's value), the simulation does weird things: It only affects every second bin. Say, we have the array 50,50,50,50,50 and I change a value to 50,50,60,50,50, it becomes 55, 50, 55, 50, 55. And. I. Don't. Know. Why.
All derivatives are just the slope in that particular point, using central differences, and the integration just goes by adding the derivative times dt.... Which is fine, since I wanted a numeric approach. However, I can't get behind the weird bin thing. Anyone got ideas on how to fix it?
On a second approach, I tried to build it from scratch using real bins this time instead of relying on pixels, and here you can see the problem of every second bin not being affected more clearly.
If anyone's curious about my motivation, I want to do two things: write a program that can simulate fluids with different methods (including more than just surface waves) and simulating simple quantum mechanical problems by solving the schrödinger equation numerically.
So, yeah. Any ideas on why it won't work would be appreciated. Have a nice day everyone!