Labset 08, 9, 10
Labset 08, 9, 10
𝒅𝒚
Program2:Solve = −𝒌𝒚
𝒅𝒕
Program code:
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
def model(y,t):
k=0.3
return -k*y
y0=5
t=np.linspace(0,20)
y=odeint(model,y0,t)
plt.plot(t,y)
plt.title("Solution of dy/dt=-ky; k=0.3, y(0)=5")
plt.xlabel('time')
plt.ylabel('y(t)')
plt.show()
Output:
Labset 09: Finding GCD using Euclid’s algorithm
Program1:Prove that 163 and 512 are relatively prime
Program code:
def gcd1(a,b):
c=1;
if b<a:
t=b;
b=a;
a=t;
while (c>0):
c=b%a;
print(a,c);
b=a;
a=c;
continue
print('GCD=',b);
gcd1(163,512)
OUTPUT:
163 23
23 2
2 1
1 0
GCD= 1
Output:
Enter the first number: 76
Enter the Secound number: 13
The GCD of 76 and 13 is 1
76 x 6 + 13 x -35 = 1
Labset 10: Solving linear congruence of the form
ax≡b(mod m)
Program1:Find the solution of the congruence 5x≡
𝟑(𝒎𝒐𝒅𝟏𝟑)
Program code:
from sympy import *
a=int(input('enter integer a'));
b=int(input('enter integer b'));
m=int(input('enter integer m'));
d=gcd(a,m)
if(b%d!=0):
print('the congruence has no integer solution');
else:
for i in range(1,m-1):
x=(m/a)*i+(b/a)
if(x//1==x):
print('the solution of the congruence is',x)
break
Output:
enter integer a 5
enter integer b 3
enter integer m 13
the solution of the congruence is 11.0