I'm learning waves in my physics class and I was wondering, how do sound waves work that make certain intervals sound good. Why does a M3/P4/P5 sound really good while m2/M2 sound (kind of) bad?
Simple frequency intervals generally sound good. Our auditory processing parts of our brains appreciate simple relationships. A perfect fourth has a 4:3 frequency ratio and a diminished fifth (arguably not a very pleasant interval) has a 45:32 frequency ratio.
If you really wanna go to the depths of this, I highly recommend "How Music Really Works", a great book:
Particular intervals don’t sound good — they sound familiar.
It all comes down to what you are used to. Which intervals were used in most of the music you have heard in your life, depending on its musical heritage. How trained your ear is to appreciate various intervals.
If you grew up in Texas and have listened to country music all your life, the intervals that are common in country music will sound good to you. If you grew up in Turkey listening to traditional Turkish music, you would prefer the intervals that are common in Turkish music. Then if you traveled, the unfamiliar music you encounter might sound jarring and dissonant to you at first, but pretty soon your ear is trained to appreciate that it is not bad, it is just different. You may grow to like it more than the music you grew up with.
A well-trained ear won’t hear any interval as bad — just different. Once your ear is well-trained you might seek out even more new intervals. For example, listening to music concrete or music that is made on historical instruments.