필터 지우기
필터 지우기

Implementing generalized cosine and sine integrals

조회 수: 7 (최근 30일)
Vera
Vera 2013년 7월 4일
hello everybody,
I have been trying to implement a formula which includes generalized sine and cosine integrals. I didn't succeed yet.
Any of you please might help me with this??
The formula is:
W = 2[ sinh^-1 (h/a) - C(2ba, 2bh) - jS(2ba, 2bh) ]
+ (j/bh) *(1 - e^(-jbh)),
where b = 57.8, h = 25 mm (0.025 m), a = 0.5 mm (0.0005 m).
C(x, y) and S(x, y) are the generalized cosine and sine integrals defined as:
C(x, y) = Integral [ cos y / t^y dt], with 0-x as integration borders
S(x, y) = Integral [ sin y / t^y dt], with 0-x as integration borders
I have been trying to calculate the S(x, y) like (same for the C(x, y)):
b = 57.8;
h = 0.025; % 25 mm
a = 0.0005; % 5 mm
k = 2* b * h;
l = 2 * b * a;
fun = @(x) sin(x) ./ (x.^k);
q = integral (fun, 0, l);
but it doesn't work.
Can, please, any of you help me with this?
Thanks in advance for your time!
  댓글 수: 3
Vera
Vera 2013년 7월 4일
hi Jan,
thanks for answering.
This is what it says:
Warning: Infinite or Not-a-Number value encountered.
> In funfun\private\integralCalc>iterateScalarValued at 349
In funfun\private\integralCalc>vadapt at 133
In funfun\private\integralCalc at 76
In integral at 89
In integral_gener_sin at 8
Would you please tell me what is the problem? I am not sure I understand it...
Thank you very much!
Oliver K
Oliver K 2013년 7월 7일
It was just the warning in the output. Didn't you get any result in q? What was your expected result of q?

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

채택된 답변

Oliver K
Oliver K 2013년 7월 8일
The approach suggested by Mike is a good one. I modified Mike's functions a little to accommodate the case where k >= 2
%%Generalized integral of cos(x)/x^k
function q = gencosint(b,k,varargin)
if k < 1
q = quadsas(@cos,0,b,-k,0,varargin{:});
elseif k == 1
q = integral(@(x) cos(x)./x,0,b,varargin{:});
else
q = -(gensinint(b,k-1,varargin{:}) + cos(b)/(b^(k-1)))/(k-1);
end
%%Generalized integral of sin(x)/x^k
function q = gensinint(b,k,varargin)
if k < 1
q = quadsas(@sin,0,b,-k,0,varargin{:});
elseif k == 1
q = integral(@(x)sin(x)./x,0,b,varargin{:});
else
q = (gencosint(b,k-1,varargin{:}) - sin(b)/(b^(k-1)))/(k-1);
end
%%example from the question
b = 57.8;
h = 0.025; % 25 mm
a = 0.0005; % 5 mm
k = 2* b * h;
l = 2 * b * a;
q = gensinint(l,k)
  댓글 수: 2
Vera
Vera 2013년 7월 8일
Thank you Oliver!
Oliver K
Oliver K 2013년 7월 11일
You are welcome. I think that I made a mistake in previous answer with the integration by parts. When doing the integration by part for cos(x)/x^k, evaluating the value of cos(x)/x^k with x=0 we would have 1/0=Inf. Similarly, for sin(x)/x^k we have 0/0.
You may want to double-check your input values though. As far as I can see, your input for k is 2.8900. Generalized integral of sine and cosine don't converge in this case.

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

추가 답변 (2개)

Walter Roberson
Walter Roberson 2013년 7월 8일
At 0, your formula comes out to 0 / 0 which is Not A Number.
integral() is supposed to be able to handle a singularity at the lower limit, so it should just be a warning.
If your results are not good you might want to look on the integral() documentation page to see how to specify tolerances.

Mike Hosea
Mike Hosea 2013년 7월 8일
Well, first of all, I think we need 0 < k < 2 for the generalized sine integral and 0 < k < 1 for the generalized cosine integral. But the main issue is that the singularity is too strong. Here is what I would suggest. Get QUADSAS
This should evaluate the generalized cosine integrals directly as well as the generalized sine integrals where k < 1. For 1 < k < 2 you can employ integration by parts and reduce the generalized sine integral to a generalized cosine integral. The "varargin" parts here are so you can pass 'AbsTol' and 'RelTol'.
function q = gencosint(b,k,varargin)
q = quadsas(@cos,0,b,-k,0,varargin{:});
function q = gensinint(b,k,varargin)
if k < 1
q = quadsas(@sin,0,b,-k,0,varargin{:});
elseif k == 1
q = integral(@(x)sin(x)./x,0,b,varargin{:});
else
q = (gencosint(b,k-1,varargin{:}) - sin(b)/(b^(k-1)))/(k-1);
end
  댓글 수: 1
Vera
Vera 2013년 7월 8일
Thank you very much for your time. Very helpful.

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

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by