I am getting an error using interp1

7 visualizaciones (últimos 30 días)
Ambali Odebowale
Ambali Odebowale el 21 de Feb. de 2022
Comentada: Ambali Odebowale el 23 de Dic. de 2022
I have table of n and k vs frequency for TiO2 and I am trying to plot the corresponding dielectrics. Here is the code
function [frequency, dielectric_function] = plot_optical_constants_TiO2(n);
color_1 = [0.7411, 0, 0.1490];
color_2 = [0.9412, 0.2314, 0.1255];
color_3 = [0.9922, 0.5529, 0.2353];
color_4 = [0.9961, 0.8, 0.3608];
color_5 = [1, 1.0, 0.3980];
set(0,'defaultaxesfontsize',20);
set(0,'defaulttextfontsize',20);
set(0,'defaultaxeslinewidth',2);
set(0,'defaultlinemarkersize',10);
set(0,'DefaultFigureWindowStyle','docked');
set(0,'DefaultFigurePosition', [0 918 1120 840]);
N_w = 1000 ; % number of points in frequency span
N_k = 2000 ; % number of points in wavevector span
w_min = 5E12;
w_max = 1e15;
[w,k_r] = ndgrid( (linspace(w_min,w_max,N_w)) , (linspace(0,50E6,N_k)) );
e_TiO2 = dlmread('e_TiO2.txt');
w_Ge = e_TiO2(:,1);
e_TiO2 = e_TiO2(:,2) + 1i*e_TiO2(:,3);
e_TiO2_interp = interp1(w_Ge, e_TiO2, w);
dielectric_function = e_TiO2_interp;
frequency = w(:,1);
figure(4)
hh = plot(w(:,1), real(e_TiO2_interp(:,1)),w(:,1), imag(e_TiO2_interp(:,1)));
legend('\epsilon''_{TiO2}', '\epsilon''''_{TiO2}')
ylabel('Dielectric Function')
xlabel('Frequency, {\omega} (rad/s)')
set(hh(1), 'color', color_3)
set(hh(2), 'color', color_1)
xlim([5e12 1e15])
end
The error is pasted below:
Error using matlab.internal.math.interp1
Sample points must be unique.
Error in interp1 (line 188)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
Error in plot_optical_constants_TiO2 (line 24)
e_TiO2_interp = interp1(w_Ge, e_TiO2, w);
  8 comentarios
Yordani
Yordani el 23 de Dic. de 2022
Hello Ambali I would like to contact you to discuss this code designed for NFRHT. Can you give me your cell phone number or email? Thank you
Ambali Odebowale
Ambali Odebowale el 23 de Dic. de 2022
odebowale.ambali.oa@gmail.com

Iniciar sesión para comentar.

Respuesta aceptada

DGM
DGM el 22 de Feb. de 2022
Strip out all the multiply-defined points:
color_1 = [0.7411, 0, 0.1490];
color_2 = [0.9412, 0.2314, 0.1255];
color_3 = [0.9922, 0.5529, 0.2353];
color_4 = [0.9961, 0.8, 0.3608];
color_5 = [1, 1.0, 0.3980];
set(0,'defaultaxesfontsize',20);
set(0,'defaulttextfontsize',20);
set(0,'defaultaxeslinewidth',2);
set(0,'defaultlinemarkersize',10);
set(0,'DefaultFigureWindowStyle','docked');
set(0,'DefaultFigurePosition', [0 918 1120 840]);
N_w = 1000 ; % number of points in frequency span
N_k = 2000 ; % number of points in wavevector span
w_min = 5E12;
w_max = 1e15;
[w,k_r] = ndgrid( (linspace(w_min,w_max,N_w)) , (linspace(0,50E6,N_k)) );
e_TiO2 = dlmread('TiO2.txt');
w_Ge = e_TiO2(:,1);
[w_Ge uidx] = unique(w_Ge);
e_TiO2 = e_TiO2(:,2) + 1i*e_TiO2(:,3);
e_TiO2 = e_TiO2(uidx);
e_TiO2_interp = interp1(w_Ge, e_TiO2, w);
dielectric_function = e_TiO2_interp;
frequency = w(:,1);
figure(4)
hh = plot(w(:,1), real(e_TiO2_interp(:,1)),w(:,1), imag(e_TiO2_interp(:,1)));
legend('\epsilon''_{TiO2}', '\epsilon''''_{TiO2}')
ylabel('Dielectric Function')
xlabel('Frequency, {\omega} (rad/s)')
set(hh(1), 'color', color_3)
set(hh(2), 'color', color_1)
xlim([5e12 1e15])

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by