There are several ways to do that, from Karplus-Strong or FM synthesis all the way to solving differential equations (usually with the finite difference method), the more work is involved the more closed is the resulting product. And it's very hard to get it right.