# Monthly Archives: December 2014

## C code using Forward Interpolation

Problem: The population of a town is given below as thousands
Year : 1891 1901 1911 1921 1931
Population : 46 66 81 93 101

Find the population of 1895 ?

Code:

Output:

## C code using lagrange method

Problem: The population of a town is given below as thousands
Year            : 1891  1901  1911  1921  1931
Population :  46       66      81      93     101

Find the population of 1895 ?

Code:

Output:

## C code using Backward Interpolation

Problem: The population of a town is given below as thousands
Year            : 1891  1901  1911  1921  1931
Population :  46       66      81      93     101

Find the population of 1895 ?

Code:

Output:

## C code using Gauss Seidel Method

Problem: Solve the following systems using gauss seidel method
5×1-x2-x3-x4=-4
-x1+10×2-x3-x4=12
-x1-x2+5×3-x4=8
-x1-x2-x3+10×4=34

Code:

Output:

## C code using Euler Method

Problem: Here we have to find dy/dx=x+y where y(0)=1 at the point x=0.05 and x=0.10 taking h=0.05

Algorithm:

1. Start
2. Define function
3. Get the values of x0, y0, h and xn
*Here x0 and y0 are the initial conditions
h is the interval
xn is the required value
4. n = (xn – x0)/h + 1
5. Start loop from i=1 to n
6. y = y0 + h*f(x0,y0)
x = x + h
7. Print values of y0 and x0
8. Check if x < xn
If yes, assign x0 = x and y0 = y
If no, goto 9.
9. End loop i
10. Stop

Code:

Output:

## C code using Runge-Kutta 4th order method

Problem: Here we have to find y(0,2) and y(0,4), Given dy/dx=1+y^2 where y=0 when x=0

Algorithm:

Step 1: input x0,y0,h,last point n

Step 2:m1=f(xi,yi)

Step 3:m2=f(xi+h/2,yi+m1h/2)

Step 4:m3=f(xi+h/2,yi+m2h/2)

Step 5:m4=f(xi+h,yi+m3h)

Step 6:yi+1=yi+(m1+2m2+2m3+m4/6)h

Step 5:Display output

Code:

Output: