# Vectorization of a function

I would like to calculate the exponential values of the elements of a list / vector. For example, I would like to calculate the Boltzmann distribution over different energy levels where the normalized population of the energy level, $$N_i$$, is calculated using the energy of those levels, $$E_i$$, and temperature($$T$$) as:

$$N_i= \frac{\exp(-\frac{E_i}{T})}{\sum {\exp(-\frac{E_i}{T})}}$$

Exp[E] doesn’t work if E is a vector. I guess I can calculate element by element for each $$N_i$$ using a loop for all i in an E[[i]], but in most language, there is a way to vectorize functions (function acting on a vector elementwise), which are generally way faster and nicer. What is the recommended “Mathematical” way to do this?

Edit: Thank you everyone for the help. It turned out I had a stupid mistake ( 11i think a 0/0 somewhere inside the vector) that is why Exp[] didn't work on a vector.

• I don't think I understand what you mean. Functions like Exp automatically thread over lists element-wise. For example: Exp[Range[5]]. Is that not what you need? Commented Nov 4, 2020 at 10:05
• Don't use E as a symbol, it's predefined! Commented Nov 4, 2020 at 10:13
• @UlrichNeumann Thanks, I will be careful.
– Greg
Commented Nov 4, 2020 at 16:47

Try

ei = RandomReal[{0, 1}, 5]
#/Total[#] &[Exp[-ei]]

• Very interesting notation and it works well, too! Thanks!
– Greg
Commented Nov 4, 2020 at 16:56

Maybe this ?

e = {1, 2, 3, 4};
Normalize[Exp[-e/T], Total]

• works very well, thanks!
– Greg
Commented Nov 4, 2020 at 16:56