Vectors must be the same length
1 次查看(过去 30 天)
显示 更早的评论
Ploting this equation numerically
and this is what I've done (below) but it says vector must be the same length. Thank you for your help
v = (0.01*2.0e-12) ;u = 5.0;
K = 8.617e-5;
T = 300; hBar = 1;
no = 10e16; dg = 1;
trig = (sin(4)*cos(4));
t = 2.0e-12; e = -1;
deltag = 0.0156;
n=[0.00 0.036 0.072];
Betag = linspace(0,10, 30); % However many you want.
p = (0.9*pi);
delta1 = deltag./(K.*T);
I0 = besseli(0,delta1); I1= besseli(1, delta1);
I2 = (I0./I1);
jog = ((no*e*deltag*dg)/hBar).*I2;
[mu] = meshgrid(-10000:100:10000);
legendStrings = cell(length(n), 1);
for k1 = 1:length(n)
thisN = n(k1);
for i = 1:length(Betag)
B1 = Betag(i);
J1 = besselj(mu,B1);
J = (J1.^2);
R = (v + (mu.*u));
S = ((v + (mu.*u)).^2);
Z = (1+thisN.*((I2.*exp(1i.*mu.*p))+1)).*trig;
tmp = ((J.*R)./(1+(2.*thisN)+(thisN.^2)+S)).*Z;
J(i) = jog.*sum(tmp(:));
end
legendStrings{k1} = sprintf('n = %.2f', thisN);
plot(Betag, real(J), '.-', 'LineWidth', 2, 'MarkerSize', 15);
hold on;
drawnow;
end
grid on;
fontSize = 20;
xlabel('\beta_\gamma', 'FontSize', fontSize)
ylabel('\it j_\gamma', 'FontSize', fontSize)
title('\it j_\gamma vs. \beta_\gamma', 'FontSize', fontSize)
legend(legendStrings, 'Location', 'best');
0 个评论
采纳的回答
Walter Roberson
2020-5-16
[mu] = meshgrid(-10000:100:10000);
mu is now a 201 x 201 array.
J1 = besselj(mu,B1);
mu is 201 x 201 so J1 is 201 x 201.
J = (J1.^2);
J is the same size as J1, 201 x 201.
J(i) = jog.*sum(tmp(:));
one of the first 30 linear-indexed elements of J is replaced, leaving it 201 x 201.
plot(Betag, real(J), '.-', 'LineWidth', 2, 'MarkerSize', 15);
You plot the vector of length 30 against the 201 x 201 array.
I suggest
for i = 1:length(Betag)
B1 = Betag(i);
J1 = besselj(mu,B1) .^ 2;
R = (v + (mu.*u));
S = ((v + (mu.*u)).^2);
Z = (1+thisN.*((I2.*exp(1i.*mu.*p))+1)).*trig;
tmp = ((J1.*R)./(1+(2.*thisN)+(thisN.^2)+S)).*Z;
J(i) = jog.*sum(tmp(:));
end
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!