필터 지우기
필터 지우기

Problem of calculating the value of integrals

조회 수: 2 (최근 30일)
Qian Feng
Qian Feng 2017년 8월 27일
편집: Qian Feng 2017년 9월 22일
Hi there, I encounter the problem of calculating the value of integrals, the code is given as follows:
r1 = 2; r2 = 4; r3 = r2 - r1;
d = 5;
syms y x real
tri = [];
for i = 1 : d
tri = [tri ; sin(20*i*x)];
end
for i = 1 : d
tri = [tri ; cos(20*i*x)];
end
tri = [1; tri];
trig = [];
for i = 1 : d
trig = [trig ; sin(20*i*x)];
end
for i = 1 : d
trig = [trig ; cos(20*i*x)];
end
trig = [1; trig];
cl1 = -log(abs(2*sin(10*x))); cl2 = int(-log(abs(2*sin(0.5*y))), 0, 20*x);
fi1 = [cl1; cl2]; fi2 = fi1;
ny1 = size(fi1,1); ny2 = size(fi2,1); ny = ny1 + ny2;
Ga1 = sym([ 0 zeros(1,d) 1./sym(1:d); 0 1./(sym(1:d)).^2 zeros(1,d)]); Ga2 = Ga1;
ep1 = fi1 - Ga1*tri; ep2 = fi2 - Ga2*trig;
epp1 = matlabFunction(ep1*ep1'); epp2 = matlabFunction(ep2*ep2');
E1 = integral(epp1,-r1,0,'ArrayValued',true); E2 = integral(epp2,-r2,-r1,'ArrayValued',true);
In my code cl1 and cl2 are the Clausen functions which can be decomposed as series of trigonometric functions. The problem is that there are Inf values in the calculation results of E1 and E2, which should not be there at all.
E1 =
0.1135 -Inf
-Inf Inf
>> E2
E2 =
0.0501 -Inf
-Inf Inf
The function cl2 itself is expressed in terms of a integration, so I am not sure if any complication will be generated by the structure of cl2 here.
Could someone help me to figure out which step I got wrong here ? Thank you !
  댓글 수: 3
Star Strider
Star Strider 2017년 8월 27일
One problem is that this term:
cl2 = int(-log(abs(2*sin(0.5*y))), 0, 20*x);
will evaluate to +Inf at 0.
Qian Feng
Qian Feng 2017년 8월 27일
This is something I did not notice before. Although the integrand has infinite value at zero, the function cl2 in fact is of finite value. I probably should change the lower limits of the integration interval into a small positive number.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2017년 8월 27일
One problem is that this term:
cl2 = int(-log(abs(2*sin(0.5*y))), 0, 20*x);
will evaluate to +Inf at 0.
I usually use ‘sqrt(eps)’ or ‘1E-8’ for zero when zero is not an option. The squared value will usually retain some small value at higher powers, eliminating the problem of a NaN or ±Inf result.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by