|
|
IGNOU > IGNOU Assignments > MCA > MCA 2009 Assignments >Numerical and Statistical Computing
IGNOU MCA Assignments
Question 1(a) Find the unique polynomial of degree 2 or less, such that f(-2) = 46, f(-1) = 4, f(3) = 156, f(4) = 484 using the Lagrange interpolation? Write a program in C evaluating the polynomial using Lagrange interpolation.

c) Using Runge-kutta method obtain y when x=1.1, given that y=1.2 when x=1 any y satisfies the equation.
Ans:
a)
f(-2)=46, f(-1)=4, f(3)=156, f(4)=484
x -2 -1 3 4
F(x) 46 4 156 484
By Lagranges formula,
f(x)=[[(x+1)(x-3)(x-4)/(-2+1)(-2-3)(-2-4)]*(46)+
[(x+2)(x-3)(x-4)/(-1+2)(-1-3)(-1-4)]*(4)]+
[(x+1)(x+2)(x-4)/(3+1)(3+2)(3-4)]*(156)+
[ (x+1)(x-3)(x+2)/(4+1)(4-3)(4+2)]*(484)]
by solving the above eqn we get,
f(x)=7x3+15.8X2-43x-48
c-code
-------
#include <math.h>
#include <stdio.h>
main()
{
float x[12],y[12];
float xtem,ytem;
int points,i,j,count;
float xval,temp,total;
scanf("%d %f\n",&points,&xval);
printf("number of points = %d xvalue to calculate = %f\n",points,xval);
printf("\nx y\n");
for (i=0;i<points;i++){
scanf("%f %f\n",&xtem,&ytem);
x[i] = xtem; y[i] = ytem;
printf("%f %f\n",xtem,ytem);
}
total = 0.0;
for (i=0;i<points;i++){
temp = 1.;
for(j=0;j<points;j++){
if (j != i) {
temp = temp * (xval - x[j]) / (x[i] - x[j]);
}
}
temp *= y[i];
total += temp;
}
printf("The value of the function at x = %f is y = %f\n\n\n",xval,total);
}
b)
Note:-All numerical coefficients of y and u which I use here should be written as suffix
For example---->>> y(0) i.e. y suffix 0 AND
u (-2) i.e. u suffix -2
Fi means special mathematical symbol
So plz consider all following terms as above
Soln:-
Here we put, x= (b-a)u+a+b/2 = 7u+8.5
y=1/x=1/7u+8.5=Fi(u)
Taking n=5, we have following
y(0)=Fi(u(0))=1/8.5=0.117647059
y(1)=Fi(u(1))=1/7u(1)+8.5=1/10.3846426=0.0962960439
y(-1)=Fi(u(-1))=1/7u(-1)+8.5=1/6.61535741=0.151163412
y(2)=Fi(u(2))=1/7u(2)+8.5=1/11.67162946=0.0856778399
y(-2)=Fi(u(-2))=1/7u(-2)+8.5=1/5.32837054=0.187674636
Substituting these values in the formula, together with the corresponding R's for n=5, we get
I=7[64/225*0.117647059+0.2393143352 (0.151163412+0.0962960439)
+0.1184634425(0.187674636+0.0856778399)]
=0.875468458
(c)
We h've given, dy/dx = 3x sqr + y sqr
y = 1.2, when x = 1
We h've to find y (1.1) i.e value of y when x = 1.1.
We take x 0 = 1, y 0 = 1.2 and h = 1.1
Here k1 =hf (x 0, y 0)
= 1.1*{3(1) sqr + 1.2 sqr }
= 4.884
k2 = hf (x 0 + 1/2 h, y 0 + 1/2 k1)
= 1.1 f (1 + 1.1/2, 1.2 + 4.884/2)
= 22.51876
k3 = hf (x 0 + 1/2 h, y 0 +1/2 k2)
= 1.1 f (1.55, 1.2 + 1/2 * 22.51876)
= 178.68801
k4=hf (x 0 + h, y 0 + k3)
= 1.1 f (2.1, 179.88801)
= 35610.21871
Therefore, y (1.1) = 2+1/6(4.884+2*22.51876+2*178.68801)
= 2+1/6(4.884+45.03752+357.37602)
= 2+1/2(407.29754)
=69.8829
  
|
|