Numerical method to solve matric for eigen values of matrix (the input of matrix is an array)?

8 次查看(过去 30 天)
Data1 = readtable('Aeiphi.xlsx');
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
T1=table2array(Data1);
freq = T1(:,2); % Frequency (in THz)
txx = T1(:,3); % Amplitude of Co-Polarozation XX
P1 = T1(:,4); % Phase of Co-Polarozation XX
tyy = T1(:,5); % Amplitude of Co-Polarozation YY
P2 = T1(:,6); % Phase of Co-Polarozation YY
txy = T1(:,7); % Amplitude of Cross-Polarozation XY
P3 = T1(:,8); % Phase of Cross-Polarozation XY
tyx = T1(:,9); % Amplitude of Cross-Polarozation YX
P4 = T1(:,10); % Phase of Cross-Polarozation YX
T_XX = txx.*exp(1i.*P1); % Transmittance of co - polarozation of XX
T_YY = tyy.*exp(1i.*P2); % Transmittance of co - polarizarion of yy
T_XY = txy.*exp(1i.*P3); % Transmittance of cross polarization of xy
T_YX = tyx.*exp(1i.*P4); % Transmittance of cross polarization of yx
TT = table(T_XX,T_YY,T_XY,T_YX);
%%%% Eigen Matrix
ii = 1:1:1002;
n = length(ii);
for i = 1:n
T = [T_XX(i,1), T_XY(i,1); T_YX(i,1), T_YY(i,1)]; % Eigen Matrix for each frequency
E = eig(T); % Eigen Values
val = [E(1,1), E(2,1)]; % Reordering the Matrix
E1(i,1) = val(:,1); % Eigen Value 1
E2(i,1) = val(:,2); % Eigen value 2
ii=ii+1;
ES1(:,1) = real(E1(:,1));
ES2(:,1) = real(E2(:,1));
ephi1(:,1) = imag(E1(:,1));
ephi2(:,1) = imag(E2(:,1));
end
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 2-by-1.
%% From eigen values separate real and imaginary part.
% (Real part: Transmission coffecient, Imaginary part: Phase)
a = abs(ES1);
b = abs(ES2);
c = ephi1;
d = ephi2;
T2 = table(a,b,c,d)
figure
plot(freq,a) % Plot of freq vs real eigen value 1 and 2
plot(freq,b)
ylim([0 1])
plot(freq,ephi1,freq,ephi2) % Plot of freq vs imag eigen value 1 and 2
ylim([-0.6 0.6])

回答(2 个)

Walter Roberson
Walter Roberson 2024-8-19
E1(i,1) = val(:,1); % Eigen Value 1
E2(i,1) = val(:,2); % Eigen value 2
ii=ii+1;
You did not initialize E1 and E2 before the loop, so E1 and E2 become initialized during the first iteration. i = 1 for the first iteration, so E1 and E2 get intialized to 1 x 1
The first iteration E1 is 1 x 1 and E2 is 1 x 1.
ES1(:,1) = real(E1(:,1));
ES2(:,1) = real(E2(:,1));
ES1 and ES2 are not initialized before the loop, so ES1 and ES2 are used. The first iteration E1 and E2 are 1 x 1, so (:,1) indexing will fetch 1 x 1, so ES1 and ES2 will get initialized to 1 x 1
The second iteration, i = 2 so E1(2,1) and E2(2,1) get assigned to, growing E1 and E2 to 2 x 1.
Then E1(:,1) is 2 x 1. But ES1 is still 1 x 1 so ES1(:,1) is a 1 x 1 extract of ES1. So the destination is 1 x 1 but the source is 2 x 1.

CHARUMATHI P R
CHARUMATHI P R 2024-8-22
It still shows error. After initializing
  2 个评论
Steven Lord
Steven Lord 2024-8-22
You probably want to use readmatrix instead of readtable followed by table2array.
Please show the modified code and the full and exact text of any warning and/or error messages you received (all the text displayed in orange and/or red in the Command Window when you run your code.)
CHARUMATHI P R
CHARUMATHI P R 2024-8-23
Data1 = readtable('D:\VIT PHD\Work 3 _ Exceptional Sensing\CST Files\Aeiphi.xlsx');
Error using readtable (line 517)
Unable to find or open 'D:\VIT PHD\Work 3 _ Exceptional Sensing\CST Files\Aeiphi.xlsx'. Check the path and filename or file permissions.
T1=table2array(Data1)
freq = T1(:,2); % Frequency (in THz)
txx = T1(:,3); % Amplitude of Co-Polarozation XX
P1 = T1(:,4); % Phase of Co-Polarozation XX
tyy = T1(:,5); % Amplitude of Co-Polarozation YY
P2 = T1(:,6); % Phase of Co-Polarozation YY
txy = T1(:,7); % Amplitude of Cross-Polarozation XY
P3 = T1(:,8); % Phase of Cross-Polarozation XY
tyx = T1(:,9); % Amplitude of Cross-Polarozation YX
P4 = T1(:,10); % Phase of Cross-Polarozation YX
T_XX = txx.*exp(1i.*P1); % Transmittance of co - polarozation of XX
T_YY = tyy.*exp(1i.*P2); % Transmittance of co - polarizarion of yy
T_XY = txy.*exp(1i.*P3); % Transmittance of cross polarization of xy
T_YX = tyx.*exp(1i.*P4); % Transmittance of cross polarization of yx
TT = table(T_XX,T_YY,T_XY,T_YX);
%%%% Eigen Matrix
ii = 1:1:1002;
n = length(ii);
E1(i,1) = val(:,1); % Eigen Value 1
E2(i,1) = val(:,2); % Eigen value 2
for i = 1:n
T = [T_XX(i,1), T_XY(i,1); T_YX(i,1), T_YY(i,1)]; % Eigen Matrix for each frequency
E = eig(T); % Eigen Values
val = [E(1,1), E(2,1)]; % Reordering the Matrix
E1(i,1) = val(:,1); % Eigen Value 1
E2(i,1) = val(:,2); % Eigen value 2
ii=ii+1;
ES1(:,1) = real(E1(:,1));
ES2(:,1) = real(E2(:,1));
ephi1(:,1) = imag(E1(:,1));
ephi2(:,1) = imag(E2(:,1));
end
%% From eigen values separate real and imaginary part.
% (Real part: Transmission coffecient, Imaginary part: Phase)
a = abs(ES1);
b = abs(ES2);
c = ephi1;
d = ephi2;
T2 = table(a,b,c,d)
figure
plot(freq,a) % Plot of freq vs real eigen value 1 and 2
plot(freq,b)
ylim([0 1])
plot(freq,ephi1,freq,ephi2) % Plot of freq vs imag eigen value 1 and 2
ylim([-0.6 0.6])
Error: Reference to cleared variable val
The left and right variable are different order (1 x 1 and 2 x 1)

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by