Professional Documents
Culture Documents
Program 1
def f(t,N):
return -0.0866*N0
N0=int(input("Enter N0 = "))
t0=int(input("Enter t0 = "))
h=float(input("Enter h = "))
n=int(input("Enter n = "))
for i in range(n):
N1=N0+h*f(t0,N0)
t0=t0+h
N0=N1
print("Value of N at t",t0,"is = ",N0)
import math as mt
def f(t):
return 200*mt.exp(-0.0866*t)
print("Exact value = ",f(30))
Err = abs(f(30)-N0)
print("Error = ",Err)
Program 3:Newton Cooling Curve
A thermometer is taken from a room at
20oC outside where T =5oC. After 1 min, the
thermometer reads 12oC. Find out the
thermometer reading after 1 more min.
Solve the differential equation using Euler’s
method
def f(t,T):
return 0.7621*(5-T)
T0=int(input("Enter T0 = "))
t0=int(input("Enter t0 = "))
h=float(input("Enter h = "))
n=int(input("Enter n = "))
for i in range(n):
T1=T0+h*f(t0,T0)
t0=t0+h
T0=T1
print("Value of T at t",t0,"is = ",T0)
import math as mt
def f(t):
return 5+15*mt.exp(-0.7621*t)
print("Exact value = ",f(2))
Err = abs(f(2)-T0)
print("Error = ",Err)
PROGRAM 4
A coil having a resistance 15 ohms and an
inductance of 10 henries is connected to 90
volts supply. Determine the value of current
after 2 seconds.
By voltage law , Ri +L di/dt = E
Solve for the above differential equation
(Take h=0.01)
def f(t,i):
return 9-1.5*i
i0=int(input("Enter i0 = "))
t0=int(input("Enter t0 = "))
h=float(input("Enter h = "))
n=int(input("Enter n = "))
for i in range(n):
i1=i0+h*f(t0,i0)
t0=t0+h
i0=i1
print("Value of current at t",t0,"is = ",i0)
import math as mt
def f(t):
return 6*(1-mt.exp(-1.5*t))
print("Exact value = ",f(2))
Err = abs(f(2)-i0)
print("Error = ",Err)
PROGRAM 5: Program 1 using Modified
Eulers method
def f(x,y):
return x+y
x0=float(input("Enter x0 = "))
y0=float(input("Enter y0 = "))
h=float(input("Enter h = "))
n=int(input("Enter n = "))
for i in range(n+1):
yp1=y0+h*f(x0,y0)
x1=x0+h
y1=y0+(h/2)*(f(x0,y0)+f(x1,yp1))
print("Value of y at x",round(x0,2),"is = ",y0)
y0=y1
x0=x1
import math as mt
def f(x):
return -x-1+mt.exp(x)
print("Exact value = ",f(0.4))