Error in Kramers-Kronig Relations

1 回表示 (過去 30 日間)
Ilvar
Ilvar 2023 年 4 月 25 日
編集済み: Walter Roberson 2023 年 4 月 25 日
I am trying to convert extinction coefficient to refractive index.
Unrecognized function or variable 'k_vec'.
Error in KramersKroigRelations (line 12)
n_vec = zeros(size(k_vec));
I tried to set up k_vec to indicate the refractive indices.
k_vec to refractive indices
clear
% read data from textinctionSpectrum.txt
data = readtable('extinctionSpectrum.txt');
wavelength = data{:,1}; % wavelength in nm
extinction = data{:,2}; % extinction coefficient
% w = 2*pi*3e17./wavelength;
% convert extinction coefficient to refractive index
n_vec = zeros(size(k_vec));
for i = 1:length(k_vec)
k = k_vec(i);
n_real = 1 + (2/pi)*integral(@(w_prime) w_prime.*k./(w_prime.^2 - w.^2), 0, Inf, 'PrincipalValue', true);
n_imag = (2/pi)*integral(@(w_prime) w.*k./(w_prime.*(w_prime.^2 - w.^2)), 0, Inf, 'PrincipalValue', true);
n_vec(i) = n_real + 1i*n_imag;
end
figure;
plot(w, real(n_real), 'b-', w, imag(n_imag), 'r-');
xlabel('Wavelength (nm)');
ylabel('Refractive index');
legend('Real part', 'Imaginary part');

回答 (1 件)

the cyclist
the cyclist 2023 年 4 月 25 日
You haven't defined a variable named k_vec before this line of code
n_vec = zeros(size(k_vec));
so MATLAB errors out when it tries to get the size of it.

カテゴリ

Help Center および File ExchangeGeographic Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by