Array indices must be positive integers or logical values.

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?

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

질문:

2020년 4월 4일

답변:

2020년 4월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by