How to make 3 different voltages in a circuit?
For the 5V, connect directly.

For 3V and 4V, a linear LDO regulator for each one. Assuming they’re low current, linear would be fine.

The LDO (low drop-out) part is important. The regulator 'overhead' (or drop-out) voltage, needs to be less than the required Vin - Vout, with your worst case (lowest) Vin.



Why LDOs?

tl; dr version: the required overhead (drop-out) between Vin (5V) and the two Vout (4V, 3V) is too low to be satisfied by a non-LDO regulator like an LM317.

Analysis

Assuming +/-10% on your 5V supply, your lowest Vin will be 4.5V. Then, the maximum overhead allowed for each of your supplies is:


4V supply: 4.5V - 4V = 0.5V
3V (3.3?) supply: 4.5V - 3V = 1.5V


Neither of these can be satisfied by a non LDO regulator like the LM317, which has an overhead (drop-out) voltage of 3V. That won't work for this setup.

So you need LDOs. These have overhead (drop-out) of about 150 - 200mV, lower than your required overhead. More about those here: https://www.analog.com/en/analog-dialogue/articles/understand-ldo-concepts.html