Vectors must be the same length

1 Ansicht (letzte 30 Tage)
Samuel Suakye
Samuel Suakye am 16 Mai 2020
Kommentiert: Samuel Suakye am 16 Mai 2020
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');

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 16 Mai 2020
[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 Kommentare
Samuel Suakye
Samuel Suakye am 16 Mai 2020
I have tried it but still having same problem
Samuel Suakye
Samuel Suakye am 16 Mai 2020
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)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Dimensionality Reduction and Feature Extraction finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by