필터 지우기
필터 지우기

Overlap integral of the electric field distribution

조회 수: 53 (최근 30일)
shdotcom shdotcom
shdotcom shdotcom 2017년 5월 19일
댓글: Suresh Chejarla 2023년 5월 25일
Hi, I am trying to calculate overlap integral (OI) of electric field distribution, using Matlab, when run the following code:
xc = linspace(0,1,M);
yc = linspace(0,1,M);
A = E1 * E2;
B = (abs(trapz(xc,trapz(yc, abs(A))) ) ).^2;
C = trapz(xc,trapz(yc, abs(E1).^2)) * trapz(xc,trapz(yc, abs(E2).^2 ));
OI = B./C;
where E1 is the electric field distribution of the desired mode and E2 is polarized mode. Both E1 and E2 are matrices of size MxM.
but, I have got this error: Error using trapz (line 57) *LENGTH(X) must equal the length of Y in dim 1.
  댓글 수: 3
shdotcom shdotcom
shdotcom shdotcom 2017년 5월 20일
You are right, I have edited the code.
Suresh Chejarla
Suresh Chejarla 2023년 5월 25일
Hello,
Can you please provide the reference for the OI expression which you have put here ?

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

채택된 답변

Torsten
Torsten 2017년 5월 19일
편집: Torsten 2017년 5월 19일
xc = linspace(0,1,M);
yc = linspace(0,1,M);
A = E1 .* E2;
B = (trapz(xc,trapz(yc, abs(A), 1)) ).^2;
C = trapz(xc,trapz(yc, abs(E1).^2, 1)) * trapz(xc,trapz(yc, abs(E2).^2, 1 ));
OI = B./C;
Best wishes
Torsten.
  댓글 수: 2
shdotcom shdotcom
shdotcom shdotcom 2017년 5월 20일
I have edited the code based on @David Goodmanson's comments. Could you please explain to me why you used 1 instead on 2 in the trapz()
C = trapz(xc,trapz(yc, abs(E1).^2, 1)) * trapz(xc,trapz(yc, abs(E2).^2, 1 ));
Torsten
Torsten 2017년 5월 22일
So the code should read:
xc = linspace(0,1,M);
yc = linspace(0,1,M);
A = E1 .* E2;
B = (trapz(xc,trapz(yc, A, 1)) )^2;
C = trapz(xc,trapz(yc, abs(E1).^2, 1)) * trapz(xc,trapz(yc, abs(E2).^2, 1 ));
OI = B./C;
I used 1 instead of 2 in trapz() because you have to integrate each column of A if you integrate over y.
Best wishes
Torsten.

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

추가 답변 (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