The appearance of infinity in the problem with finding the minimum of a function
Mostra commenti meno recenti
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?
Risposte (2)
Here is what I discovered. When
,

and

atanh(1)
4 Commenti
This is how
looks like:
looks like:x = -5:0.0001:5;
y = atanh(x);
z = tanh(x);
plot(x, y, x, z), hold on
plot(x, x, '--'), grid on, xlabel x, ylabel y
xticks(-5:5), axis square
legend('atanh(x)', 'tanh(x)', '', 'location', 'eastoutside')
Yuriy Yerin
il 9 Mag 2024
Modificato: Yuriy Yerin
il 9 Mag 2024
Yuriy Yerin
il 9 Mag 2024
When
,
and
.
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
Ganesh
il 9 Mag 2024
0 voti
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!
1 Commento
Yuriy Yerin
il 9 Mag 2024
Categorie
Scopri di più su 2-D and 3-D Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

