Info

This question is closed. Reopen it to edit or answer.

A calculation doesn't give the original picture when done in reverse

1 view (last 30 days)
I'm working on a project with electric fields and I need to do some simple mathematical calculation. Given the and , which are related by
,
I need to find the coefficients . For that, the integral
,
should be evaluated. Now, I have my and given as 100x100 by matrices and my code is as follows:
NOTE: I couldn't upload the E_m.mat (1x312 cell which includes a 100x100 matrix in each cell) due to its size. You can just create some random complex matrices and try it in this way. My problem is independent of the exact values inside these matrices as you will see below.
%% 1. INITIAL PARAMETERS
coreRadius = 100; pixel = 100; % load(E_m.mat,E_m)
%% 2. CREATE THE INPUT FIELD
% Gaussian input field
% taken from "Thomas Dideriksen - Custom 2D Gauss - Mathworks File Exchange", the link is:
% https://www.mathworks.com/matlabcentral/fileexchange/9556-custom-2d-gauss
inputField = MMFcreateGaussian([pixel,pixel], 100, 100, 0, 0, 6, [0,0]);
At this point plotting abs(inputField).^2 gives...
Gaussian.png
%% 3. FIND THE WEIGHT OF EACH FIELD IN THE INPUT GAUSSIAN PROFILE
% i.e. solve the overlap integral in the second formula
% normalize each field
% Here, I want to make the absolute square of any field E_m to be equal to "1"
for i = 1:length(E_m)
E_m{i} = E_m{i} ./ sqrt( sum( abs( E_m{i}(:) ).^2 ) );
end
% find the conjugate of each field
% This is necessary for finding a_m (check the first equation above)
for k = 1:length(E_m)
conjE_m{k} = conj(E_m{k});
end
% find all a_m's and try to re-create the original inputField above
for mode = 1:length(E_m)
a_m{mode} = sum(sum( conjE_m{mode} .* inputField )); % finding a_m's in the second equation
outputField{mode} = a_m{mode} .* E_m{mode}; % multiplying each a_m with the corresponding E_m
end
% sum every field to obtain the total field
totalOutField = sum(cat(3,outputField{:}),3);
What I did in the last lines can be expressed by the formula
,
which should be equal to my initial input field, i.e. . Thus, when I plot abs(totalOutField).^2 I should get the same picture as above. But, what I get instead is...
outIntensity.png
This process is very important for my project and I'm stuck on that for almost two days. Any help will be appreciated. What's wrong with this program?
  2 Comments
David Goodmanson
David Goodmanson on 3 Jul 2019
Hi Sahin,
What do your basis fields E_m{i} look like? This process is not going to work unless they form and orthonormal set, i.e.
Int E_m{i}*E_m{j} dxdy = 1 i=j (which you are addressing)
= 0 i~=j
is that the case for i~=j?
Because of this requirement, using random matrices for test purposes is not going to succeed.
Sahin Kurekci
Sahin Kurekci on 3 Jul 2019
@David, you are right. After I read your comment this morning I immediately checked the orthogonality of the matrices (I've done the normalization earlier) and I saw that they were not orthgonal to each other. This was really weird for me since I took the matrices from an already-working program written by someone else. I reshaped matrices into vectors, applied a Gram-Scmidth procedure and checked the orthogonality again. I coouldn't manage to obtain an orthogonal set even in this case (that's probably because the number of matrices is smaller than the number of elements in each matrix; this is also weird) and decided to make some more research on the theory. I'll update this post when I find a solution or stuck at something else. I was really angry with myself after reading your comment because I disregarded such a simple but crucial thing; your comment was really enlightning in that way.

Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!