Array indices must be positive integers or logical values.
1 次查看(过去 30 天)
显示 更早的评论
hFig = figure
clc;
v = 2.0;u = 2.0;
K = 8.617e-5;
trig = sin(4)*cos(4);
p = 2.7; t = 2.0; e = 1.6022e-19;
deltag = 0.0156; deltaxi = 0.0204;
n=[0.00 0.20 0.50 1.00];
T = linspace(0,700, 30); % However many you want.
delta1 = deltag./(K.*T); delta2 = deltaxi./(K.*T);
B0xi = besseli(0,delta2); B1xi = besseli(1, delta2);
B0g = besseli(0, delta1); B1g = besseli(1, delta1);
q = ((K^2).*T)./(e^2); g = p./(K.*T);
a = (B0g./B1g)- (2./delta1);
b = (1 - ((3./delta1).*(B0g./B1g)) + 6./(delta1.^2));
c = (1 - ((B1xi./B0xi).*(1./delta2)));
legendStrings = cell(length(n), 1);
for k1 = 1:length(n)
thisN = n(k1);
sigma = ((1i.*u-1-v.^2)./(v.^2-u.^2 +1-2i.*u)).*(1./(v.^2 +1));
sigmapri = thisN * ((1i.*u-1-v.^2)./((1+(thisN.*t)).^2 +v.^2).*(v.^2-u.^2 +1-2i.*u)).*(((B0g./B1g).*exp(0.9i.*pi))-(v./(v.^2 +1)));
w = sigma + sigmapri;
m = (w.*q.*trig((g.^2)-(2.*delta1.*g.*a)-(2.*delta2.*g.*(B1xi./B0xi))+((delta1.^2).*b)+(delta1.*delta2.*a.*(B1xi./B0xi))+((delta2.^2).*c)));
legendStrings{k1} = sprintf('n = %.2f', thisN);
plot(T, real(m), '.-', 'LineWidth', 2, 'MarkerSize', 15);
hold on;
drawnow;
end
grid on;
fontSize = 20;
xlabel('T(K)', 'FontSize', fontSize)
ylabel('\chi_\gamma', 'FontSize', fontSize)
title('\chi_\gamma vs. Temp(K)', 'FontSize', fontSize)
legend(legendStrings, 'Location', 'northeast');
% Maximize the figure window.
hFig.WindowState = 'maximized';
0 个评论
采纳的回答
Sriram Tadavarty
2020-4-4
Hi Samuel,
In the calculation of m in the for loop, trig value is not multiplied instead accessed with a value. This is the source of the error. Update that line of code as below:
m = (w.*q.*trig.*((g.^2)-(2.*delta1.*g.*a)-(2.*delta2.*g.*(B1xi./B0xi))+((delta1.^2).*b)+(delta1.*delta2.*a.*(B1xi./B0xi))+((delta2.^2).*c)));
Hope this helps.
Regards,
Sriram
0 个评论
更多回答(1 个)
Steven Lord
2020-4-4
m = (w.*q.*trig((g.^2)-(2.*delta1.*g.*a)-(2.*delta2.*g.*(B1xi./B0xi))+...
((delta1.^2).*b)+(delta1.*delta2.*a.*(B1xi./B0xi))+((delta2.^2).*c)));
You meant to multiply trig by the expression that follows it, not to use that expression to index into the (scalar) trig variable, right?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!