This lecture we will practice some Basic MATLAB Scripts.
We will start with simple scripts and will discuss some electrical engineering applications.
Program to calculate Electricity bill.
w = input('Enter power of your device (in watts): ');
h = input('Enter time (in hours): ');
r = input('Enter electricity rate (in dollars per KWH): ');
ec = w * h/1000 * r;
disp(’Your Electricity bill is’)
Disp(ec)
Power transfer vs Load resistance curve
RL = 1:0.01:10;
Vs = 12;
Rs = 2.5;
P = (Vs^2*RL)./(RL+Rs).^2;
plot(RL,P)
xlabel('Load resistance')
ylabel('Power dissipated')
Torque-Speed Curve for a squirrel cage Induction Motor
Ns=1500; % Synchronous speed;
R1=15.6 ;R2=14;X1=18; X2=23;Xm=260;Vt=400/sqrt(3);
s = 0.002:0.002:1; % vector of slip
N = Ns.*(1-s); % Speed, in RPM
Ws = 2*pi*Ns/60; % Synchronous speed in rad/sec
Rr = R2./ s; % Rotor resistance
Zr = j*X2 + Rr; % Total rotor impedance
Za = j*Xm*Zr./(j*Xm+Zr); % Air-gap impedance
Zt = R1 + j*X1 +Za; % Terminal impedance
Ia = Vt ./ Zt; % Terminal Current
I2 = j*Xm*Ia./(j*Xm+Zr); % Rotor Current
Pag = 3* (abs(I2)).^2.*Rr; % Air-Gap Power
Pm = Pag.* (1-s); % Converted Power
Trq = Pag/ Ws; % Developed Torque
subplot(2,1,1)
plot(N, Trq)
xlabel('Speed in RPM')
ylabel('Torque (Nm)')
subplot(2,1,2)
plot(Ia, Trq)
xlabel('Load Current')
ylabel('Torque (Nm)')
We will start with simple scripts and will discuss some electrical engineering applications.
w = input('Enter power of your device (in watts): ');
h = input('Enter time (in hours): ');
r = input('Enter electricity rate (in dollars per KWH): ');
ec = w * h/1000 * r;
disp(’Your Electricity bill is’)
Disp(ec)
Power transfer vs Load resistance curve
RL = 1:0.01:10;
Vs = 12;
Rs = 2.5;
P = (Vs^2*RL)./(RL+Rs).^2;
plot(RL,P)
xlabel('Load resistance')
ylabel('Power dissipated')
Torque-Speed Curve for a squirrel cage Induction Motor
Ns=1500; % Synchronous speed;
R1=15.6 ;R2=14;X1=18; X2=23;Xm=260;Vt=400/sqrt(3);
s = 0.002:0.002:1; % vector of slip
N = Ns.*(1-s); % Speed, in RPM
Ws = 2*pi*Ns/60; % Synchronous speed in rad/sec
Rr = R2./ s; % Rotor resistance
Zr = j*X2 + Rr; % Total rotor impedance
Za = j*Xm*Zr./(j*Xm+Zr); % Air-gap impedance
Zt = R1 + j*X1 +Za; % Terminal impedance
Ia = Vt ./ Zt; % Terminal Current
I2 = j*Xm*Ia./(j*Xm+Zr); % Rotor Current
Pag = 3* (abs(I2)).^2.*Rr; % Air-Gap Power
Pm = Pag.* (1-s); % Converted Power
Trq = Pag/ Ws; % Developed Torque
subplot(2,1,1)
plot(N, Trq)
xlabel('Speed in RPM')
ylabel('Torque (Nm)')
subplot(2,1,2)
plot(Ia, Trq)
xlabel('Load Current')
ylabel('Torque (Nm)')