How can i polt the negative values in my code?

Hello im strugling to find a way to plot my code here
clc
clear
%Motor Parameters
V1 = 469.5;
nph = 3;
poles = 4;
fe = 60;
R1 = 0.9174;
X1 = 0.005473*2*pi*fe;
Xm = 0.1854*2*pi*fe;
X2 = 0.005473*2*pi*fe;
R2 = 0.6258;
%Calculating syncronus speed
omegas = 4*pi*fe/poles;
ns = 120*fe/poles;
%Stator thenvenin equivelent
Z1eq = 1i*Xm*(R1 + 1i*X1)/(R1 + 1i* (X1+Xm));
R1eq = real(Z1eq);
X1eq = imag(Z1eq);
V1eq = abs(V1*1i*Xm/(R1 +1i*(X1 + Xm)));
%Slip loop
for x = 1:200
s(x) = x/50;
rpm(x) = ns*(1-s(x));
I2 = abs(V1eq/(Z1eq + 1i*X2 + R2/(s(x))));
Tmech(x) = nph*(I2^2)*R2/(s(x)*omegas);
end
plot(Tmech,rpm)
xlabel('Tmech')
ylabel('rpm')
it is a torque-speed graph for a motor. i con not figure our how i can get negative values of x and always giving me Array indices must be positive integers or logical values.
Error in Speed_torqe_graphing (line 37) s(x) = x/50;
any help is really appreciated.

 Accepted Answer

Adam Danz
Adam Danz on 18 Jul 2018
Edited: Adam Danz on 18 Jul 2018
Instead of using x to represent the values you'd like to test, use x as the index values of a vector 'q' that contains the values you'd like to test.
Replace your for-loop with this to test values -200 to 200
%Slip loop
q = -200:1:200;
for x = 1:length(q)
s(x) = q(x)/50;
rpm(x) = ns*(1-s(x));
I2 = abs(V1eq/(Z1eq + 1i*X2 + R2/(s(x))));
Tmech(x) = nph*(I2^2)*R2/(s(x)*omegas);
end
[ update] You don't need the for-loop, by the way. All of the code above can rewritten as:
q = -200:1:200;
s = q/50;
rmp = ns * (1-s);
I2 = abs(V1eq./(Z1eq + 1i*X2 + R2./s));
Tmech = nph*(I2.^2)*R2./(s.*omegas);

More Answers (0)

Categories

Products

Release

R2018a

Community Treasure Hunt

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

Start Hunting!