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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkVnygGzKhC8_YirDvC178NJ5zUYSV-C3ijiUEKV9j1H4CJAzBItag7zkMWUFW0_f6ehjCzL7jYWnYAzenE-NeFgvR2qiMPnO32kVi5STdssMxFyEM7ijKdF1S2TLxfZ8UgjKUKoBuHS0/s320/inductionmotor.png)
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)')
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgM80uRaLoZWc-1FUv06ie0wVP96ZxfW4_XNPAyDoAbUaE-E7_FF2ZWG31U0v_F5dcFg0zqAHMO1RcyXYZdcMlhePaLmANH2mak_mC_N03cJTfHOFhP1W0VL_yNvM4AV5o3yFO3LkOIwfI/s320/scriptexamples.png)
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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkVnygGzKhC8_YirDvC178NJ5zUYSV-C3ijiUEKV9j1H4CJAzBItag7zkMWUFW0_f6ehjCzL7jYWnYAzenE-NeFgvR2qiMPnO32kVi5STdssMxFyEM7ijKdF1S2TLxfZ8UgjKUKoBuHS0/s320/inductionmotor.png)
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)')