Integrals function computing accelerating

조회 수: 1 (최근 30일)
Sara
Sara 2012년 7월 18일
Hi Guys ,
- trapz
- cumtrapz
function int = Fcn_integ(x,k,dt)
x ... Signal to integration
k ... Number of integrations to be undertaken
dt ... Sampling of the signal to integration
I have implemented the above function for integration. Then I want to know it is possible to use the built-in integration function e.g., cumtrapz for this issue?Can it be helpful? Is this built-in function more optimal? By the length of x to 2500 , I have the total time around 0.642 second. Thanks in advance
  댓글 수: 1
Jan
Jan 2012년 7월 18일
How could we compare TRAPZ with your function, without knowing your function?
"More optimal" is not possible: Optimal is optimal already. "More efficient" or "faster" are more correct.

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

답변 (1개)

Jan
Jan 2012년 7월 18일
The best idea is to try it. While our suggestion will be pure speculation, because we do not know your function, you have all required data and programs to check this by your own.
  댓글 수: 1
Sara
Sara 2012년 7월 19일
I marked the two implementation (Part One and Part Two)that should give the same result , but it does not do so. The part two is correct and I want to convert it to part one with the same result. Could any one give some hints on that? It is the main part of my implementation on trapezoid method to implement integration function .
Part one :
lenx=length(x);
if k <= 0
int = x ;
return
end
int = zeros(1,length(x));
c=(k-1)/factorial(k-1);
y1 = x(2:lenx)' ;
y2 = x(1:lenx-1)' ;
tm1= dt*cumsum(tril(ones(lenx-1,lenx-1),0),1);
ans1=((tm1.^c)*y1)*dt/2;
ans2=((tm1.^c)*y2)*dt/2;
int(3:lenx) = ans1(1:lenx-2)+ ans2(2:lenx-1);
---------------------------------
Part two :
if k <= 0
int = x ;
return
end
int = zeros(1,length(x));
c=(k-1)/factorial(k-1);
dth2=dt/2;
lenx=length(x);
cmn=(lenx:-1:0)*dt;
ft1=cmn.^(c);
ft2 = (cmn+dt).^(c);
for n = 3:lenx
y1 = x(2:n) ;
t1 = ft1(lenx-n+3:lenx+1) ;
y2 = x(1:n-1) ;
t2 = ft2(lenx-n+3:lenx+1);
int(n) = sum (t1.*y1 + t2.*y2)*dth2 ;
end

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

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by