Arduino DUE has a built-in DAC (has two in fact) and so you can do arbitrary function generation fairly easily by just going over some arbitrary table (that sampled the function) and output that with
analogWrite to the DAC channel[s]; details in this arduino.cc tutorial. They only show sine/triangle/square waves there, but if you look at Waveforms.h at the end of that tutorial you can put arbitrary shapes in there.
By the way this technique of waveform generation of using a lookup table and a DAC is abbreviated DDS for Direct Digital Synthesizer.
Here's a more conceptual tutorial on DDS (not involving arduino):
The DACs built-in Arduino DUE have 12-bit resolution by the way, i.e. 4096 discrete output levels. IF you need better than that, an external DAC is required, which you could connect by TWI/SPI etc.
You can get a poor man's DAC on the Arduino UNO or Leonardo by PWMing with
analogWrite on the GPIO pins (as suggested in the other answer), but you need understand low pass filter fundamentals to get that done.