How do I fix "Index in position 2 exceeds array bounds (must not exceed 1)."
2 次查看(过去 30 天)
显示 更早的评论
clc;
clear;
close all;
%% Data
% Define the parameters
qe = 1;
n = 5e16;
p = 0.525;
E_0 = 10e3;
v_s = 3.5e3;
epsilon_d = 50;
ue = 1;
m0 = 9.1094e-31;
m = 0.44 * m0;
epsilon_0 = 1;
h = 4.1356e-15;
hBar = h / (2 * pi);
b = 0.142e-9;
a = 3 * b / (2 * hBar);
tt = 2.6;
delta = 5.7 / 2;
G = sqrt(delta^2 + 5 * tt^2);
% Define the range for ω_p and B^(-1)
omega_p = linspace(0, 10, 150);
B_inv = linspace(0.04, 1, 150);
k_q = omega_p / v_s;
v = (-2 * tt^2 * a * sin(p * a) / G);
tau = ue * p / (qe * v);
tau_1 = tau / 2;
omega_c = qe * B_inv' * v / p;
gamma = 1 + 1i * omega_c * tau_1;
sigma_g = qe^2 * n * v * tau / p;
Six = p^2 / (2 * pi * hBar^2);
Rix = 2 * p / m / v;
b_g = 2 * pi * hBar^2 * epsilon_0 * v / (qe^2 * p);
beta_g = (k_q' .* v) ./ omega_c;
% Initialize the result matrix
j_x = zeros(numel(omega_p), numel(B_inv));
% Calculate sigma_xx
sigma_xx = zeros(numel(omega_p), numel(B_inv));
for r = -3:3
J_r = besselj(r, beta_g);
sigma_xx = sigma_xx + (2 * sigma_g' * J_r) ./ (1 - 1i * (omega_p' - r * omega_c) * tau);
end
% Calculate R_x
R_x = zeros(numel(omega_p), numel(B_inv));
for r = -3:3
J_r = besselj(r, beta_g);
R_x = R_x + (omega_c' ./ k_q) .* (J_r .^ 2) ./ (1 - 1i * (omega_p' - r * omega_c) * tau);
end
% Calculate g(omega_q, k_q)
g_omega_q_k_q = 1 + 1i / (epsilon_0 * (epsilon_d + 1)) * (sigma_xx ./ (v_s - R_x));
% Calculate the equation for each combination of omega_p and B^-1
for i = 1:numel(omega_p)
for j = 1:numel(B_inv)
sum_term = 0;
for r = -1:1
J_r = besselj(r, beta_g(i));
sum_term = sum_term + J_r / (1 - 1i * (omega_p(i) - r * omega_c(j)) * tau);
end
j_x(i, j) = (1 / (2 * qe * n * v(i))) * ((tau * omega_c(j) * p^2) / (8 * pi * (hBar^2))) * (abs((sigma_g(i, j) * E_0) / g_omega_q_k_q(i, j)))^2 ...
* ((1 / beta_g(i)) / (1 + (omega_c(j)^2 * tau_1^2)))^2 * (sum_term) ...
* (-1i * gamma(i, j)^2 * (sum_term + 1) * besselj(sum_term + 1, beta_g(i)) + 1i * conj(gamma(i, j))^2 * (sum_term - 1) * besselj(sum_term - 1, beta_g(i)));
end
end
% Plot the results
[Omega_P, B_inv] = meshgrid(omega_p, B_inv);
surf(Omega_P, B_inv, j_x);
xlabel('\omega_p');
ylabel('B^{-1}');
zlabel('j_x');
title('Plot of j_x against \omega_p and B^{-1}');
title('Plot of j_x against \omega_p and B^{-1}');
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!