Вы находитесь на странице: 1из 12

MEPE 508 Module 1: Programming and Simulations Assignment 4 Edvan Moyo Question 1

Matlab Code Program % Program to create a Multiplication Table a=input('enter a number to show its multiplication table '); clear num for k=1:a; for h=1:10; num(k,h)=k*h; end end disp(num) Results

1 2 3 4 5 6 7 8 9 10

2 4 6 8 10 12 14 16 18 20

3 6 9 12 15 18 21 24 27 30

4 8 12 16 20 24 28 32 36 40

5 10 15 20 25 30 35 40 45 50

6 12 18 24 30 36 42 48 54 60

7 14 21 28 35 42 49 56 63 70

8 16 24 32 40 48 56 64 72 80

9 18 27 36 45 54 63 72 81 90

10 20 30 40 50 60 70 80 90 100

Question 2
Matlab Code Program % Program to produce a Power Delta Curve x = 0 : pi/20 : pi; v1= input ('Enter the induced voltage: '); v2= input ('Enter the terminal voltage:'); %X= input ('Enter the machine rectance: '); for X=1:5; P = v1*v2*sin(x)/X; plot(P,x) hold on title ('Power Delta Curves') xlabel ('Power') ylabel ('\theta') set(gca,'YTick',0:pi/6:pi) set(gca, 'YTickLabel',{'0','pi/6','pi/3','pi/2','2*pi/3','5*pi/6','pi'}) end Results
Power Delta Curves

pi

5*pi/6

2*pi/3

pi/2 pi/3 pi/6 0 0

0.5

1.5

2.5 Power

3.5

4.5 x 10

5
4

Question 3a
Matlab Code Program % Program to calculate the electricity tarrif unit= input('input the number of units consumed: '); rate1=4; rate2=7.9; rate3=9.8; if unit <= 20; bill = 20*rate1; elseif unit <= 100 bill = (unit-20)*rate2 + 20*rate1; else bill = (unit-120)*rate3 + 100*rate2 + 20*rate1; end disp( 'Your bill in Ruppees for this month is:' ) disp(bill)

Results input the number of units consumed: 18 Your bill in Ruppees for this month is: 80 input the number of units consumed: 78 Your bill in Ruppees for this month is: 538.20 input the number of units consumed: 205 Your bill in Ruppees for this month is: 1703 Question 3b
Matlab Code Program % Program to calculate units consumed cost = input('Enter the amount paid: ') rate1=4; rate2=7.9; rate3=9.8; if cost <= 80; unit = cost/rate1; elseif cost <= 712 unit = cost/rate2 - (20*rate1/rate2)+20; else

unit = cost/rate3 - (100*rate2/rate3) - (20*rate1/rate3) + 120; end disp( 'Your units consumed (in kwh) for this month are:' ) disp(unit)

Results Enter the amount paid: 78 Your units consumed (in kwh) for this month are: 19.5 Enter the amount paid: 538.20 Your units consumed (in kwh) for this month are: 78 Enter the amount paid: 1703 Your units consumed (in kwh) for this month are: 205

Question 4
Matlab Code Program % Program to enter details of students enter = 'y'; n=1; while enter =='y'; Students{1,n}= input ('Enter the name of the Student in the MEEPE_EnPe Program: ','s'); enter = input ('Press "y" if you want to enter another name. ','s'); n = n+1; end

Results Enter the name of the Student in the MEEPE_EnPe Program: Nitu Press "y" if you want to enter another name. y Enter the name of the Student in the MEEPE_EnPe Program: Bharat Press "y" if you want to enter another name. y Enter the name of the Student in the MEEPE_EnPe Program: Rubal Press "y" if you want to enter another name. y Enter the name of the Student in the MEEPE_EnPe Program: Shyam Press "y" if you want to enter another name. y Enter the name of the Student in the MEEPE_EnPe Program: Kusang Press "y" if you want to enter another name. >> Students Students = 'Nitu' 'Bharat' 'Rubal' 'Shyam' 'Kusang'

Question 5
Matlab Code Program % Program to check the Grade based on the score grade= input('Enter the grade obtained: ') if grade < 40; disp ('Grade F'); elseif (grade < 49) && (grade >= 40) disp ('Grade D'); elseif (grade < 54) && (grade >= 50) disp ('Grade C'); elseif (grade < 59) && (grade >= 55) disp ('Grade C Plus'); elseif (grade < 64) && (grade >= 60) disp ('Grade B Minus'); elseif (grade < 69) && (grade >= 65) disp ('Grade B'); elseif (grade < 74) && (grade >= 70) disp ('Grade B plus'); elseif (grade < 79) && (grade >= 75) disp ('Grade A Minus'); elseif(grade < 100) && (grade >= 80); disp ('Grade A'); else disp ('Out of range'); end

Results Enter the grade obtained: 35 Grade F Enter the grade obtained: 76 Grade A Minus Enter the grade obtained: 98 Grade A Enter the grade obtained: 56 Grade C Plus Enter the grade obtained: 65 Grade B

Question 6
Matlab Code Program % Program to count square numbers between any two limits count=0; n=1; enter=1; while (enter== 1); a=input('Enter the lower limit of the interval: '); b=input('Enter the higher limit of the interval: '); %x=1; while (n<=b)%b is the higher limit count=0; for i=(1:1:b/2) n=i^2; if(n>=a)&&(n<=b) count=count+1; end

end end disp('Number of total square numbers are: ') disp(count) enter=input('Press 1 if you to count more square number between limits else 0: '); n=1; end

Results Enter the lower limit of the interval: 5 Enter the higher limit of the interval: 45 Number of total square numbers are: 4 Press 1 if you to count more square number between limits else 0: 1 Enter the lower limit of the interval: 46 Enter the higher limit of the interval: 201 Number of total square numbers are: 8 Press 1 if you to count more square number between limits else 0: 0

Question 7
Matlab Code Program

Results

Question 8
Matlab Code Program %program to test if a given number is a prime number p = input ('Please enter a number: '); n=primes(p); if any(n==p) disp('This is a prime number') disp(p) else disp('This is not a prime number') disp(p) end

Results Please enter a number: 37 This is a prime number 37 Please enter a number: 78 This is not a prime number 78

Question 9
Matlab Code Program %Program to replace multipes of 5 whenever found with 4000 clc enter=1; while(enter==1) m=input('Enter the number of rows of the matrix: '); n=input('Enter the number of columns of the matrix: '); for i=(1:1:m) for j=(1:1:n) mat(i,j)=input('Enter the elements of the matrix, element by element: '); end end disp('The original matrix created is: ') disp(mat) for i=(1:1:m) for j=(1:1:n) a=rem(mat(i,j),5); if(a==0) mat(i,j)=4000; end end end disp('The new matrix created is: ') disp(mat) enter=input('To analyse another matrix enter 1 or enter to terminate the program: '); mat=0; end

Results
Enter the number of rows of the matrix: 2 Enter the number of columns of the matrix: 4 Enter the elements of the matrix, element by Enter the elements of the matrix, element by Enter the elements of the matrix, element by Enter the elements of the matrix, element by Enter the elements of the matrix, element by Enter the elements of the matrix, element by Enter the elements of the matrix, element by Enter the elements of the matrix, element by The original matrix created is: 23 24 20 15 10 5 60 23 The new matrix created is: 23 24 4000 4000 4000 4000

element: element: element: element: element: element: element: element:

23 24 20 15 10 5 60 23

4000 23

Question 10
Matlab Code Program R1=0.332; R2=0.4; R3=0.5; f=50; p=input('enter number of poles of the generator (Note number of poles should be even):') Ws=120*f/p; Re=0.59; X2=0.464; Xe=1.106; s=1:-0.1:0; b=[1 1 1 1 1 1 1 1 1 1 1]; Vph=input('enter the phase voltage:'); N=3*Vph^2*R1*b; % numerator for T1 N1=3*Vph^2*R2*b; % numerator for T2 N2=3*Vph^2*R3*b; % numerator for T3 n1=Ws.*s; n2=(Re+R1./s).^2; n2a=(Re+R2./s).^2; n2b=(Re+R3./s).^2; n3=(Xe+X2)^2; n4=n3.*b; n5=n1.*(n2+n4); % denominator for T1 n6=n1.*(n2a+n4);% denominator for T2 n7=n1.*(n2b+n4);% denominator for T3 T1=N./n5; % Torque for resistor R1 T2=N1./n6; % Torque for resistor R2 T3=N2./n7; % Torque for resistor R3 plot(s,T1,'r',s,T2,'y', s,T3,'b') title('Plot of Torque Vs Slip') xlabel('Slip') ylabel ('Torque')

Results With p=2 Vph 230


Plot of Torque Vs Slip 12

11

10

9 Torque

5 0

0.1

0.2

0.3

0.4

0.5 Slip

0.6

0.7

0.8

0.9

Question 11
Matlab Code Program

Results

Вам также может понравиться