필터 지우기
필터 지우기

Vectors must be the same length

조회 수: 1 (최근 30일)
Samuel Suakye
Samuel Suakye 2020년 5월 16일
댓글: Samuel Suakye 2020년 5월 16일
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');

채택된 답변

Walter Roberson
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
  댓글 수: 2
Samuel Suakye
Samuel Suakye 2020년 5월 16일
I have tried it but still having same problem
Samuel Suakye
Samuel Suakye 2020년 5월 16일
after the correction, this is what I had but the graphs are not distinct (see below). How do we make it distinct as in the legend
(see below)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by