19MA211 SNM Record
19MA211 SNM Record
Marks
S. No. Date Name of the Program Page No. Remarks
Awarded
Lagrange’s Interpolation
3
method
4 Trapezoidal rule
Question:
Aim:
Algorithm:
Program:
def f(x):
return x**3-x-2
def f1(x):
return 3*x**2-1
xo=float (input ("Enter the initial approximation: "))
for i in range (1,10):
xn=xo-f(xo)/f1(xo)
xo=xn
print ("The approximate root using Newton-Raphson method is %.4f"%xn)
Output:
Result:
Program 2: Gauss-Seidel method
Question:
Aim:
Algorithm:
Program:
Output:
Result:
Program 3: Lagrange’s Interpolation method
Question:
Using Lagrange interpolation formula, find the value corresponding to 𝒙 = 𝟏𝟎 from the
following table
x 0 1 2 4 5 6
y 1 14 15 5 6 19
Aim:
Algorithm:
Program:
x= [0,1,2,4,5,6]
y= [1,14,15,5,6,19]
s=float (input ("Enter the value of x to be in: "))
sum=0
for i in range (0,6):
prod=1
for j in range(0,6):
if i!=j:
prod=prod*(s-x[j])/(x[i]-x[j])
sum=sum+prod*y[i]
print ("The functional value is %.4f"%sum)
Output:
Result:
Program 4: Trapezoidal rule
Question:
𝟏
Evaluate ∫ 𝒅𝒙 using trapezoidal rule with 𝒉 = 𝟎. 𝟐.
𝟎 𝟏+𝒙𝟐
Aim:
Algorithm:
Program:
def f(x):
return 1/(1+x**2)
a=float (input ("Enter the lower limit: "))
b=float (input ("Enter the upperlimit: "))
h=float (input ("Enter the step size: "))
n=int((b-a)/h)
sum=0
for i in range (1, n):
sum=sum+f(a+i*h)
trap=h/2*(f(a)+f(b)+2*sum)
print ("The Integral value is %.5f"%trap)
Output:
Result:
Program 5: Runge-Kutta method of fourth order
Question:
Find 𝒚(𝟎. 𝟐), given that 𝒅𝒚 = 𝒙 + 𝒚𝟐, 𝒚(𝟎) = 𝟏 using Runge-Kutta fourth order method.
𝒅𝒙
Aim:
Algorithm:
Program:
Output:
Result:
Program 6: Adam’s predictor and corrector method
Question:
Evaluate (𝟏. 𝟒) , given that 𝒅𝒚 = 𝒙𝟐(𝟏 + 𝒚), 𝒚(𝟏) = 𝟏, 𝒚(𝟏. 𝟏) = 𝟏. 𝟐𝟑𝟑, 𝒚(𝟏. 𝟐) = 𝟏. 𝟓𝟒𝟖
𝒅𝒙
and 𝒚(𝟏. 𝟑) = 𝟏. 𝟗𝟕𝟗 using Adam’s predictor and corrector method.
Aim:
Algorithm:
Program:
Output:
Enter x0: 1
Enter y0: 1
Enter x1: 1.1
Enter y1: 1.233
Enter x2: 1.2
Enter y2: 1.548
Enter x3: 1.3
Enter y3: 1.979
Approximate solution is 2.5749
Result: