It is a really challenging problem to generate synthetic sounds that sound natural. There are many techniques - some simple, some really complex. To get good results you will have to use one of the more complex algorithms.
- Subtractive synthesis
- Additive synthesis
- Granular synthesis
- Wavetable synthesis
- Frequency modulation synthesis
- Phase distortion synthesis
- Physical modeling synthesis
- Sample-based synthesis
- Subharmonic synthesis
This are some synthesis methods taken from Wikipedia. Physical modeling can produce really good sounds but this shows in the complexity of the method - the idea is simple, the implementation hard.
You should probably start with additive synthesis. For this just add sine waves of the fundamental frequency and integer multiplies. For example 440 Hz, 880Hz, 1320 Hz, ... The amplitude should drop exponentially with the frequency. Information about the structure of the components is best found in scientific papers about music instrument analysis. Finally you must modulate the amplitude of the signal with an timevarying envelope. The structure for a guitar can be found in mentioned papers, too.
The links from cdonner (Plucking a Guitar String - Karplus-Strong algorithm) and Dervin Thunk (Physical modeling) sound promising. A really simple approximation of full physical modeling with differential equations. Maybe quite limited to guitar strings and similar instruments, but exactly what you are looking for and surely simpler to do than tuning a additive model. I will try it myself if I find some time over the weekend; really exited what one can get out of the algorithm.