I want to find the so-called "efficiency" of a function, defined as the ratio of the difference of the absolute values of the maximum and minimum to their sum. My very simple code is as follows
phi0=1.90132; theta0=1*pi/2;
I1=cos(x/2).*atanh(sin(x/2));
I2=cos((x+2*phi0)/2).*atanh(sin((x+2*phi0)/2));
I3=cos((x+2*theta0)/2).*atanh(sin((x+2*theta0)/2));
eff=(I_max-abs(I_min))/(I_max+abs(I_min))
plot(x,I_sum,'LineWidth',3)
set(gca,'FontName','Times New Roman','FontSize',34)
xlabel('\phi','FontName','Times New Roman','fontsize',34,'fontweight','b');
ylabel('I','FontName','Times New Roman','fontsize',34,'fontweight','b');
set(gca,'XTick',-pi:pi/2:pi)
set(gca,'XTickLabel',{'-\pi','-\pi/2','0','\pi/2','\pi'})
However, for theta0=pi/2 , I suddenly get infinity for the minimum of the function, even though the plot does not contain infinity.
At the same time for a very close value theta0=0.99999999*pi/2 everything works fine.
What is the reason for this strange behavior?
Update. And how to avoid singularity in calculations?