Array indices must be positive integers or logical values.

3 ビュー (過去 30 日間)
Samuel Suakye
Samuel Suakye 2020 年 4 月 4 日
回答済み: Steven Lord 2020 年 4 月 4 日
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';

採用された回答

Sriram Tadavarty
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

その他の回答 (1 件)

Steven Lord
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?

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by