Numerical Method Model Question

Tribhuwan University
Institute of Science and Technology
Model Question
Bachelor Level / Third Semester / Science
Computer Science and Information Technology ( CSC207 )
( Numerical Method )
Full Marks: 60
Pass Marks: 24
Time: 3 hours
Candidates are required to give their answers in their own words as far as practicable.
The figures in the margin indicate full marks.

Group A

Attempt any TWO questions.     (10X2=20)

1. Compare Gauss Elimination method and Gauss Jordan method of solving simultaneous equation. Use Gauss Elimination to solve the following system of equation and also write its algorithm.

    2x+3y+4z=5

    3x+4y+5z=6

    4x+5y+6z=7

10 marks view

Comparison between Gauss Elimination method and Gauss Jordan method

  • In Gauss- elimination method, the augmented matrix is reduced to Echelon form using row operations and then back substitution is applied to get values of unknowns, occurring in a system of linear equations.
  • In Gauss-Jordan method, the augmented matrix is reduced to reduced Echelon form using elementary row operations to obtain values of unknowns of a system of linear equations.
  • For small system it more convenient to use Gauss Jordan method.
  • Gauss Jordan requires more computational work than Gauss Elimination.

Given system of equation,

    2x+3y+4z=5

    3x+4y+5z=6

    4x+5y+6z=7

The augmented matrix of given system is;

Applying, 

Applying, 

Now, using backward substitution;

3z = 0

i.e. z = 0


Finding the value of y using the value of z


Again, finding the value of x using the value of y and z


Hence the value of x, y, z are -2, 3, 0 respectively.


Algorithm for Gauss elimination method

1. Start

2.  Read the order of matrix ‘n’ and take the coefficients of linear equation.

3.  Do for k=1 to n-1

     Do for i=k+1 to n

     Do for j=k+1 to n+1

     a[i][j]=a[i][j]-a[i][k]/a[k][k]*a[k][j]

     end for j

     end for i

     end for k

4. Compute x[n]=a[n][n+1]/a[n][n]

5. Do for k=n-1 to 1

       Sum=0

    Do for j=k+1 to n

     Sum=Sum+a[k][j]*x[j]

    end for j

      x[k]=(a[k][n+1]-Sum)/a[k][k]

     end for k

6. Display the result x[k]

7. Stop

2. Write an algorithm and a program to compute the interpolation value at a specific point, given a set of data points, using Lagrange interpolation method.

10 marks view

Algorithm For Lagrange’s interpolation

1.      Read the number of data ‘n’.

2.      Read the value at which value is needed (say y).

3.      Read available data points x and f(x).

4.      for i=0 to n

for j=0 to n

if(i!=j)

L[i]=L[i]*(y-x[j])/(x[i]-x[j])

end if

end for

end for

5.      for i=0 to n

sum=sum+L[i]*f[i]

end for

6.      Print interpolation value ‘sum’ at y.

Stop

Program

#include<stdio.h>

#include<conio.h>

int main()

{

  float x[10], f[10], y, sum=0.0, l;

 int n, i, j;

 printf("\\nInput number of data:");

 scanf("%d", &n);

 printf("\\nInput data points x(i) & f(i):\\n"); for(i=0;i<n;i++)

{

   printf("x[%d]=",i);

   scanf("%f", &x[i]);

   printf("f[%d]=",i);

   scanf("%f", &f[i]);

}

printf("\\nFunctional value:");

scanf("%f", &y);

for(i=0;i<n;i++)

{

   l=1;

   for(j=0;j<n;j++)

  {

    if(j!=i)

    {

      l=l*(y-x[j])/(x[i]-x[j]);

    }

 }

sum=sum+l*f[i];

}

printf("\\nValue at %f=%f", y, sum);

getch();

return 0;

}

3. Derive Composite Simpson’s 1/3 Rule for numerical integration. How does it improve the accuracy of integration?

10 marks view

Here, the integration interval is divided into n number of segments of equal width, where n is even number. Then the step size is

We have from simpson’s 1/3 rule,


Therefore,



This equation is called composite Simpson’s 1/3 rule.

It improves the accuracy of integration formulae by locating integration points in special locations. 

Group B

Attempt any EIGHT questions.     (5X8=40)

4. Write a program to solve a non linear equation using bisection method.

5 marks view

#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<stdlib.h>

float f ( float x)

{

   float y;

   y= pow(x, 2)+x -2;

   return y;

}

void main()

{

   float x1, x2, x0, error=0.0001;

   int i=0;

   printf("\\nEnter two initial guess:");

   scanf("%f%f", &x1, &x2);

   if (f(x1 )*f(x2 )>0)

   {

      printf("\\nWrong Input!!");

      exit(0);

   }

else

{

   do

      {

         x0=(x1+x2)/2;

         if(f(x0 )*f(x1 )>0)

                   x1=x0;

         else

                   x2=x0;

        i++;

      }while(fabs (f(x0))>error);

   }

printf("\\nRoot=%f", x0);

printf("\\nNumber of iteration=%d",i);

getch();

}

5. Find the roots of the following equations using Newton’s method.

     log x – cos x = 0

5 marks view

Given,

Let the initial guess be 0.5.

Now, let us calculate the root using tabular form.


Here, the 4th and 5th iteration has same value of x2 up to 2 decimal place, so that root of given equation is 1.42.

6. Estimate the value of ln(3.5) using Newton’s backward difference formula, given the following data


5 marks view

The difference table is

Here,

Now according to Newton’s backward difference formula;


7. Fit a straight line to the following set of data.


5 marks view

We have,

Therefore the linear equation is

y = a + bx

i.e. y = 1.6 + 1.2x

8. Estimate the first derivative of f(x)=ln x at x=1 using the second order central difference formula.

5 marks view

Given,

     f(x)=ln x

let h=0.1

We have central divided difference formula for second order is





= -1.009

9. Compare and contrast between Jacobi iterative method and Gauss Seidal method. 

5 marks view

Both the Jacobi and Gauss-Seidel methods are iterative methods for solving the linear system Ax = b.

In the Jacobi method the updated vector x is used for the computations only after all the variables (i.e. all components of the vector x) have been updated. On the other hand in the Gauss-Seidel method, the updated variables are used in the computations as soon as they are updated.

Thus in the Jacobi method, during the computations for a particular iteration, the “known” values are all from the previous iteration. However in the Gauss-Seidel method, the “known” values are a mix of variable values from the previous iteration (whose values have not yet been evaluated in the current iteration), as well as variable values that have already been updated in the current iteration.

Even though the Gauss-Seidel’s method uses the improved values as soon as they are computed, this does not ensure that the Gauss-Seidel’s method would converge faster than Jacobi iterations.

Consider a system of linear equation;

Then, these equation can be written as;

From Gauss Jacobi approximation; we have, (with initial approximation x1 = a, x2 = b & x3 = c)

And, from Gauss Seidel approximation;


10. Explain about boundary value problem with example? Differentiate it with initial value problem

5 marks view

Boundary Value Problem

Consider the following linear second order differential equation,

Suppose we are interested in solving this differential equation between the values x = a & z = b. Hence a & b are two values such that a<b. Let us divide the interval [a, b] into n equal subintervals of length h each.

Let x0, x1,.....,xn be the pivotal points and a & b are called the boundary points. Solving the differential equation means finding the values of y0, y1, ....., yn. Suppose y0 and yn are given. That is the solution values at the boundary points are given. Then the differential equation is called a Boundary Value Problem. So, the following is the general form of a boundary value problem.

Difference between Initial value and Boundary value problem

An initial value problem has all of the conditions specified at the same value of the independent variable in the equation (and that value is at the lower boundary of the domain, thus the term “initial” value). On the other hand, a boundary value problem has conditions specified at the extremes of the independent variable. For example, if the independent variable is time over the domain [0,1], an initial value problem would specify a value of y(t) and y‘(t) at time t = 0, while a boundary value problem would specify values for y(t) at both t = 0 and t = 1.

11. Use the Heun's method to estimate y(0.4) when

    y’(x)=x2 +y2 with y(0)=0. Assume h=0.2

5 marks view

Here,

1st iteration:

2nd iteration:

Here,


 

12. Solve the Poisson’s equation ∇ 2 f=2x2 y 2 over the square domain 0 <= x <= 3 and 0 <= y <= 3 with f=0 on the boundary and h=1.

5 marks view

Given Poisson’s eqn. is

h = 1

Let’s divide the domain into grids of 3 x 3 with f = 0 at the boundary as below

 

Now, from the difference equation for the Poisson’s equation,





Solving these equations,

Using eq.(ii) in (iii)



Using eq.(ii) in (iv)


& we have eq. (i)


Solving equation (a), (b) & (i) we get,

Using these values in eq. (ii)