The appearance of infinity in the problem with finding the minimum of a function
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
function z=cur_phi_T_0
x=-2*pi:0.001:2*pi;
r1=1;r2=1;
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));
I_sum=(I1+r1*I2+r2*I3);
I_min=min(I_sum)
I_max=max(I_sum)
eff=(I_max-abs(I_min))/(I_max+abs(I_min))
plot(x,I_sum,’LineWidth’,3)
grid on
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’})
end
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?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
function z=cur_phi_T_0
x=-2*pi:0.001:2*pi;
r1=1;r2=1;
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));
I_sum=(I1+r1*I2+r2*I3);
I_min=min(I_sum)
I_max=max(I_sum)
eff=(I_max-abs(I_min))/(I_max+abs(I_min))
plot(x,I_sum,’LineWidth’,3)
grid on
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’})
end
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? 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
function z=cur_phi_T_0
x=-2*pi:0.001:2*pi;
r1=1;r2=1;
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));
I_sum=(I1+r1*I2+r2*I3);
I_min=min(I_sum)
I_max=max(I_sum)
eff=(I_max-abs(I_min))/(I_max+abs(I_min))
plot(x,I_sum,’LineWidth’,3)
grid on
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’})
end
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? plotting, infinity MATLAB Answers — New Questions