필터 지우기
필터 지우기

Numerical integration Error in size of elements

조회 수: 1 (최근 30일)
farzad
farzad 2014년 2월 11일
편집: Azzi Abdelmalek 2014년 2월 11일
Hi all
I have a function to integrate , the problem is , for any amount of x that contains zero , the size of g matrix becomes one smaller , like x : 1x19 and g :1x18 , what happens to g when I calculate it's square root ??? what changes the dimension ? since this integration needs that x and g be of the same dimension
x=[-p/2:1:p/2];
f= c*sin(a/p*x);
g=sqrt(1+(diff(f)).^2);
integ=trapz(x,g)

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 2월 11일
편집: Azzi Abdelmalek 2014년 2월 11일
Because diff will reduce the length of g , use
integ=trapz(x(1:end-1),g)
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2014년 2월 11일
Farzad commented
Thank you so much Azzi , just to know about it , why diff reduces the length ? and there is one other command : derivative , can it be used in this condition ? in general ?
Azzi Abdelmalek
Azzi Abdelmalek 2014년 2월 11일
편집: Azzi Abdelmalek 2014년 2월 11일
You can use gradient function

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

추가 답변 (0개)

카테고리

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