There are two different ways to produce a voltage source. The first is to put a variable resistor in series with the power source, which you can adjust to control the voltage. This works, but dissipates a lot of heat. The second is to put a switch in series with the power source and a capacitor in parallel with the load, then switch the power source on and off very rapidly and use the duty cycle to control the voltage. This is how modern switching power supplies work. In actual practice, there are also inductors in the circuit which cause resonance, and allow the switching to happen when there is no current flowing through the switch. This is how modern switching power supplies can be so efficient.