The profiler shows, that almost the complete time is spent in this line:
if max(abs(f_n - f) / f_n) < epsilon
Are you sure, that this calculates what you expect? For n=5, abs(f_n - f) / f_n is a 25x25 matrix. Using the max function replies a vector and to provide a scalare condition for the if command Matlab inserts an all() implicitly. Is this, what you want? Or maybe:
if max(abs((f_n - f) ./ f_n)) < epsilon
This is much faster, but another criterion and the results of the function are different.
Yur code does not contain meaningful comments, which explain, what you want to calculate. Then it is hard to guess, if you have implemente what was intented.