function t=calculate_layers(n,t1,z) %% calculate layer thicknesses given nlayers and top and bottom exp_sum = @(x) ( x.^(n-1)-1)./(x-1)-z/t1; f = fzero(exp_sum,[1.0001 2]); t = t1*f.^(0:(n-2));