The appearance of infinity in the problem with finding the minimum of a function

2 views (last 30 days)
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?

Answers (2)

Sam Chak
Sam Chak on 9 May 2024
Here is what I discovered. When ,
and
atanh(1)
ans = Inf
  4 Comments
Yuriy Yerin
Yuriy Yerin on 9 May 2024
Yes, thanks, I realized that while plotting the graph Matlab avoids infinity (because of the chosen interval for x) and it is looking for the minimum because it can't find the limit in its algorithm.
Sam Chak
Sam Chak on 9 May 2024
When , and .
In pure mathematics, zero times infinity is undefined. But it appears to smoothly join the discontinuities if is very small.
dx = 0.01;
x = -2:dx:2;
y = cos(x*pi/2).*atanh(sin(x*pi/2));
plot(x, y), grid on, xlabel x, ylabel y

Sign in to comment.


Ganesh
Ganesh on 9 May 2024
You are encountering this issue, as the value of "I_sum(1)" when theta0 = pi/2 is indeed "-Inf". You can try to manually calculate "I1", "I2" and "I3", and you will find "I3" to be "-Inf" when x=-2*pi.
You are not able to see the value on the graph as the plot is interpolated. You would find that at x=0, you will attain a value of "Inf" for "I3". However, your array does not contain x=0.
Mathematically, this should be treated as a discontinuity. The only workaround for the same is to modify the array "x" so that the domain is valid for the mathematical equations.
I hope this helps!

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!