Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

Practical 1 A

clc;
disp('In a college, 120 mathematics students can opt for either French(F),German(G) or
Russian(R)')
n=120;
F=65;
G=45;
R=42;
FandG=20;
FandR=25;
GandR=15;
FandGandR=8;
disp('using Inclusion Exclusion Principle')
ForGorR=F+G+R-FandG-FandR-GandR+FandGandR;
disp(ForGorR,'Number of students studying French or German or Russian')
FGnR=FandG-FandGandR;
disp(FGnR,' Number of students studying French or German but not Russian ')
FRnG=FandR-FandGandR;
disp(FRnG,' Number of students studying French and Russian but not German')
GRnF=GandR-FandGandR;
disp(GRnF,' Number of students studying German and Russian but not French ')
OF=F-FGnR-FandGandR-FRnG;
disp(OF,' Number of students studying only French ')
OG=G-FGnR-FandGandR-GRnF;
disp(OG,' Number of students studying only German')
OR=R-FRnG-FandGandR-GRnF;
disp(OR,' Number of students studying only Russian’)
K=n-ForGorR;
disp(K,'Number of students studying any of the languages')

Output

Number of students studying French or German or Russian

100.

Number of students studying French or German but not Russian


12.

Number of students studying French and Russian but not German

17.

Number of students studying German and Russian but not French

7.

Number of students studying only French

28.

Number of students studying only German

18.

Number of students studying only Russian

10.

Number of students studying any of the languages

20.

Prac 1B
Code

clc;
U1=1;
U2=5;
P=[]
for i=1:2
P(i)=3^i-2^i;
disp(P(i));
end
disp('P(1)=U(1) and P(2)=U(2)');
disp('Hence Un=3^n-2^n for all n belonging to N')

output

1.

5.

P(1)=U(1) and P(2)=U(2)

Hence Un=3^n-2^n for all n belonging to N

PRACT 2A
CODE

clc;
function [k]=fact(a)
k=-1;
if(a<0|a>200)
disp("Invalid")
break;
else
if(a==1|a==0)
k=1;
else
k=a*fact(a-1)
end
end
endfunction
a=4;
p=fact(a);
disp(p,'The value of 4! is')

OUTPUT

The value of 4! is
24.

PRACT 2B
CODE

clc;
x=poly(0,'x')
p=2*x^3-7*x^2+4*x-15;
disp(p,'The polynimial is')
k=horner(p,5)
disp(k,'value of the polynomial at x=5 is')

OUTPUT

The polynimial is

2 3

- 15 + 4x - 7x + 2x

value of the polynomial at x=5 is

80.

PRACT 2C

CODE

clc;
V=int32([258,60])
thegcd=gcd(V);
disp(thegcd,'The gcd of the two number 258 and 60 is')

OUTPUT

The gcd of the two number 258 and 60 is


6

PRACTICAL 3A

clc;
M=8;
F=5;
T=M+F;
disp(T,'No. of ways a student can choose a calculus professor')
E=[2,3,5,7];
F=[2,4,6,8];
G=intersect(E,F);
H=length(E)+length(F)-length(G);
disp(H,'Event of getting an even or a prime number')
E=[11,13,17,19];
F=[12,14,16,18];
G=union(E,F);
K=length(G);
disp(K,'no of ways of choosing a number which is prime or even')

OUTPUT

No. of ways a student can choose a calculu

s professor

13.

Event of getting an even or a prime number

7.
no of ways of choosing a number which is p

rime or even

8.

Practical 3B

Code:

clc;

display("To find : factorial of a 6")

facto2=2*1;

facto3=3*facto2

disp(facto3 , 'facto3')

facto4=3*facto3

disp(facto4 , 'facto4')

facto4=4*facto3

disp(facto4 , 'facto4')

facto5=5*facto4

disp(facto5 , 'facto5')

facto6=6*facto5

disp(facto6, 'facto6')

k=8*7*factorial(6) /factorial(6) ;

disp(k, 'value of 8! /6! is:')

j=12*11*10*factorial (9) /factorial(9) ;

disp(j, 'value of 12! /9! is:')


Output:

To find : factorial of a 6

facto3=

facto4=

18

facto4=

24

facto5=

120

facto6=

720

value of 8! /6! is:

56

value of 12! /9! is

1320

PRACT 3C
CODE

clc;
disp('finding the number of 3 letters word using only given six letters (A,B,C,D,E,F) without repetition')
n=6;
l1=n;
l2=n-1;
l3=n-2;
k=l1*l2*l3;
disp(k,'number of three letter word possible')

OUTPUT
finding the number of 3 letters word using only given six letters (A,B,C,D,E,F) without repetition

number of three letter word possible

120.

PRACTICAL 4A

clc;
disp('Experiment:Three coins are tossed and the the number of heads are observed')
S=[0,1,2,3];
disp('The probability space is as follows')
P0=1/8;
P1=3/8;
P2=3/8;
P3=1/8;
disp('A is the event that atleast one head appears and B is the event that all heads or all
tails appers')
A=[1,2,3];
B=[0,3];
PA= P1+P2+P3;
disp(PA,'Probability of occurrence of event A')
PB=P0+P3;
disp(PB,'Probability of occurrence of event B')

OUTPUT

Experiment:Three coins are tossed and the


the number of heads are observed

The probability space is as follows

A is the event that atleast one head appears and B is the event that all heads or all tails appers

Probability of occurrence of event A

0.875

Probability of occurrence of event B


0.25
PRACTICAL 4B

clc;
disp('Experiment:selection of student out of 100 student')
M=30;
C=20;
T=100;
PM=M/T
disp(PM)
PC=C/T
disp(PC)
MnC=10;
PMnC=MnC/T
disp(PMnC)
PMorC=PM+PC-PMnC;
disp(PMorC,'Probability of selected taking mathmatics or chemistry')

output

Experiment:selection of student out of 100 student

0.3

0.2

0.1

Probability of selected taking mathmatics or chemistry

0.4

PRACTICAL 4C

clc;
disp("Experiment:A die is tossed and the outcomes are observed");
disp("to find:Probability (PM) of an event that one of the dies is 2 if the sum is 6");
E=["(1,5)","(2,4)","(3,3)","(4,2)","(5,1)"]
disp(E,’E=’)
A=["(2,1)","(2,2)","(2,3)","(2,4)","(2,6)","(1,2)","(3,2)","(4,2)","(5,2)","(6,2)"]
disp(A,’A=’)
B=intersect(A,E)
disp(B,’B=’)
PM=2/5
disp(PM,’PM=’)

OUTPUT

Experiment:A die is tossed and the outcomes are observed

to find:Probability (PM) of an event that one of the dies is


2 if the sum is 16
E=
!(1,5) (2,4) (3,3) (4,2) (5,1) !

column 1 to 8
A=
!(2,1) (2,2) (2,3) (2,4) (2,6) (1,2) (3,2) (4,2) !

column 9 to 10

!(5,2) (6,2) !
B=

!(2,4) (4,2) !
PM=
0.4

PRACTICAL 5

clc;
disp('to find minimal spanning tree')
disp('the adjancy matrix for the weighted graph of 6 nodes is:')
K=[0 0 7 0 4 7;0 0 8 3 7 5;7 8 0 0 6 0;0 3 0 0 0 4;4 7 6 0 0 0;
7 5 0 4 0 0]
disp(K)
disp('Edges of the graph')
AC=7;
AE=4;
AF=7;
BC=8;
BD=3;
BE=7;
BF=5;
CE=6;
DF=4;
M=[AC,AE,AF,BC,BD,BE,BF,CE,DF];
V=int32(M);
L=gsort(V)
disp(L,"L")
disp('deleting edges without disconnecting the graph until 5 edges remain')
N=[BE,CE,AE,DF,BD];
Sum=sum(N);
disp(Sum,'Weight of minimal spanning tree is')
disp('another method of finding minimal spanning tree is ')
K=gsort(V,'g','i')
disp(K,"K")
N2=[BD,AE,DF,CE,AF];
Sum2=sum(N2);
disp(Sum2,'weight of the minimal spanning tree is is')

OUTPUT

to find minimal spanning tree

the adjancy matrix for the weighted graph of 6 nodes is:

0. 0. 7. 0. 4. 7.
0. 0. 8. 3. 7. 5.
7. 8. 0. 0. 6. 0.
0. 3. 0. 0. 0. 4.
4. 7. 6. 0. 0. 0.
7. 5. 0. 4. 0. 0.

Edges of the graph

L=

8 7 7 7 6 5 4 4 3

deleting edges without disconnecting the graph until 5 edges remain

Weight of minimal spanning tree is

24.

another method of finding minimal spanning tree is


K

3 4 4 5 6 7 7 7 8

weight of the MST is

24.

PRACTICAL 6A

clc;
A=[0 0 0 1;1 0 1 1;1 0 0 1;1 0 1 0];
disp(A,'Adjancency matrix of graph G is')
A2=A^2
disp(A2,'A2')
A3=A^3
disp(A3,'A3')
disp('the no. of ones A is equal to the number of edges in the graph i.e 8')

OUTPUT

Adjancency matrix of graph G is

0. 0. 0. 1.
1. 0. 1. 1.
1. 0. 0. 1.
1. 0. 1. 0.

A2

1. 0. 1. 0.
2. 0. 1. 2.
1. 0. 1. 1.
1. 0. 0. 2.

A3

1. 0. 0. 2.
3. 0. 2. 3.
2. 0. 1. 2.
2. 0. 2. 1.

the no. of ones A is equal to the number of edges in the gra


ph i.e 8

Prac 6b
Code:

clc;
A=[0 0 0 1;1 0 1 1;1 0 0 1;1 0 1 0];
disp(A,'adjacency matrix of graph G is')
A4=A^4;
A3=A^3;
A2=A^2;
B4=A+A2+A3+A4;
B4=[4 11 7 7 0 0 0 0 3 7 4 4 4 11 7 7];
for i=1:16
if(B4(i)~=0) then B4(i)=1;
end
end
disp(B4,'replacing nonzero enteries of B4 with 1 we get path (reachability)matrix P is')
disp('there are zero enteries in P,therefore graph is not strongly connected')

output

adjacency matrix of graph G is

0. 0. 0. 1.
1. 0. 1. 1.
1. 0. 0. 1.
1. 0. 1. 0.

replacing nonzero enteries of B4 with 1 we get path (reachability)matrix P is

1. 1. 1. 1. 0. 0. 0. 0. 1. 1. 1. 1. 1. 1. 1. 1.

there are zero enteries in P,therefore graph is not strongly connected

prac 7a

clc;
disp('division algorithm')
a=4461;
b=16;
r=modulo(a,b)
disp('r',r)
K=fix(a/b)
disp('K=',K)
j=b*K+r
disp('j=',j)
a=-262
b=3
K=fix(a/b)
disp('K=',K)
r=modulo(a,b)
disp('r=',r)
j=b*K+r
disp('j=',j)
disp('a&j have equal values hence division algorithm is proved')

output
division algorithm

13.

278.

K=

4461.

j=

- 87.

K=

- 1.

r=

- 262.

j=

a&j have equal values hence division algorithm is proved

Practical7b
clc;
disp('divisibility and primes')
x=50;
disp('prime no. less than 50 are')
y=primes(x)
disp('y=',y)
disp('the prime factorisation of 21,24 and 1729 respectively are')
K=factor(21)
disp('K=',K)
l=factor(24)
disp('l=',l)
n=factor(1729)
disp('n=',n)

OUTPUT

divisibility and primes

prime no. less than 50 are

2. 3. 5. 7. 11. 13. 17. 19. 23. 29. 31. 37. 41. 43. 47.

y=

the prime factorisation of 21,24 and 1729 respectively are

3. 7.

K=

2. 2. 2. 3.

l=

7. 13. 19.

n=

PRAC 7 C

CODE

clc;
x=poly(0,'x');
g=3*x^2-7*x+5
disp('g=',g)
m=horner(g,2)
disp('n=',n)
n=horner(g,8)
disp('n=',n)
j=m-n
disp('j=',j)
disp(n,'For n=')
if(modulo(j,6)==0) then
mprintf('% i is congruent to % i (mod6)',m,n)
end

OUTPUT

2
5 - 7x + 3x

g=

141.

n=

141.

n=

- 138.

j=

For n=

141.
3 is congruent to 141 (mod6)

PRAC 8 A

clc;
a=(8-4)-3
b=8-(4-3)
disp('since a and b are not equal so subtraction is non-commutative on z(set of integers)')
a=[1 2;3 4]
disp(a,'a=')
b=[5 6;0 -2]
disp(b,'b=')
g=a*b
disp(g,'g=')
k=b*a
disp(k,'k=')
disp('Since g&k are not equal matrix multiplication is non-commutative')
h=(2^2)^3
disp(h,'h=')
j=2^(2^3)
disp(j,'j=')
disp(‘Since h and j are not equal so exponential operation is non associative on the sets of positive
intergers N’)
OUTPUT

since a and b are not equal so subtraction is non-commutative on z(set of integers)

a=

1. 2.
3. 4.

b=

5. 6.
0. - 2.

g=

5. 2.
15. 10.

k=

23. 34.
- 6. - 8.

g&k are not equal matrix multiplication is non-commutative

h=

64.

j=
256.
Since h and j are not equal so exponential operation is non associative on the sets of positive intergers N

PRAC 8B

clc;
t=poly(0,'t');
f=t^3+t^2-8*t+4
disp(f,'f=')
g=factors(f)
disp(g,'g=')
disp(r=roots(f),'Roots of f(t) are as follows:')
t=poly(0,'t')
h=t^4-2*t^3+11*t-10
disp(r=roots(h),'The equal root so fh(t) are 1 and 2')

OUTPUT
f=

2 3
4 - 8t + t + t

g=

(1)

3.5615528 + t

(2)

-2+t

(3)

- 0.5615528 + t

Roots of f(t) are as follows:

- 3.5615528
2.
0.5615528

The equal root so fh(t) are 1 and 2

- 2.
1.5 + 1.6583124i
1.5 - 1.6583124i
1.

PRAC 9 A

clc;
b=[0,1];
for i=1:2
for j=1:2
k=b(i)& b(j);
disp(k)
end
end
for i=1:2
for j=1:2
k=b(i)|b(j);
disp(k)
end
end
k=~b
clear;
D=[1,2,5,7,10,14,35,70];
a=35;
b=70;
V=int32([a,b]);
thelcm=lcm(V)
disp(thelcm,'thelcm=')
V=int32([a,b]);thegcd=gcd(V)
disp(thegcd,'thegcd=')
abar=70/a
disp(abar,'abar=')

OUTPUT

T
F

thelcm=

70

thegcd=

35

abar=

2.

PRAC9 B

clc;
D=[1,2,5,7,10,14,35,70];
a=2;
b=14;
V=int32([a,b]);
thelcm=lcm(V)
disp(thelcm,'thelcm=')
V=int32([a,b]);thegcd=gcd(V)
disp(thegcd,'thegcd=')
abar=70/a
disp(abar,'abar=')
bbar=70/b
disp(bbar,'bbar=')
j=[abar,b];
n=[a,abar];
V=int32([j])
disp(V,'V=')
lcm1=lcm(V)
disp(lcm1,'lcm1=')
K=int32([n])
disp(K,'K=')
lcm2=lcm(K)
disp(lcm2,'lcm2=')
OUTPUT

thelcm=

14

thegcd=

abar=

35.

bbar=

5.

V=

35 14

lcm1=

70

K=

2 35

lcm2=

70
PRAC 10

clc;
disp('The recurrence relation a[n]=11*a[n-1]-39*a[n-2]+45*a[n-3]')
x=poly(0,'x');
g=x^3-11*x^2+39*x-4
disp(g,'Characteristics polynomial equation for a above recurrence realation')
j=[];5,
j=roots(g);
disp(j,'Roots of characteristic equation j1,j2')
disp('Hence the general solution isa[n]=c1*(3^n)+c2*n*(3^n)+c3*(5^n)')
disp('Initial condition at n=0 and n=1 respectively are')
a0=5;
a=11
a2=25;
D=[1 0 1;3 3 5;9 18 25];
K=[5 11 25]
disp(K,'K=')
c=[];
c=D/K;
c1=c(1)
disp(c1,'c1=')
c2=c(2)
disp(c2,'c2=')
c3=c(3)
disp(c3,'c3=')
disp('Thus solution is a[]=(4-2*n)(3^n)+5^n')

OUTPUT

The recurrence relation a[n]=11*a[n-1]-39*a[n-2]+45*a[n-3]

Characteristics polynomial equation for a above recurrence relation

2 3
- 4 + 39x - 11x + x

Roots of characteristic equation j1,j2


5.4471579 + 2.8595654i
5.4471579 - 2.8595654i
0.1056841

Hence the general solution isa[n]=c1*(3^n)+c2*n*(3^n)+c3*(5^n)

Initial condition at n=0 and n=1 respectively are

K=

5. 11. 25.

c1=

0.0389105

c2=

0.2243839

c3=

1.1258106

thus solution is a[]=(4-2*n)(3^n)+5^n

You might also like