You are on page 1of 5

Sadaf Saeed NM Assignment EE-20309

QUESTION NO 01:

DATA:

S.no x y
1 0 2
2 1 8
3 2 7
4 3 10
5 4 15
6 5 25
7 6 309

WORKING:
FITTING STRAIGHT LINE :

S.no x y squared x xy
1 0 2 0 0
2 1 8 1 8
3 2 7 4 14
4 3 10 9 30
5 4 15 16 60
6 5 25 25 125
7 6 309 36 1854
Sum = 21 376 91 2091

GRAPH:
Sadaf Saeed NM Assignment EE-20309

FITTING PARABOLA (QUADRATIC):

S.no x y squared x xy x^2(y) x^3 x^4


1 0 2 0 0 0 0 0
2 1 8 1 8 8 1 1
3 2 7 4 14 56 8 16
4 3 10 9 30 270 27 81
5 4 15 16 60 960 64 256
6 5 25 25 125 3125 125 625
7 6 309 36 1854 11124 216 1296
Sum = 21 376 91 2091 15543 9261 194481

GRAPH:

FITTING CUBIC CURVE:

squared
S.no x y xy x^2(y) x^3 x^4 x^3(y) x^5
x
1 0 2 0 0 0 0 0 0 0
2 1 8 1 8 8 1 1 8 1
3 2 7 4 14 56 8 16 56 32
4 3 10 9 30 270 27 81 270 243
5 4 15 16 60 960 64 256 960 1024
6 5 25 25 125 3125 125 625 3125 3125
7 6 309 36 1854 11124 216 1296 66744 7776
Sum = 21 376 91 2091 15543 9261 194481 71163 12201
Sadaf Saeed NM Assignment EE-20309

GRAPH:
Sadaf Saeed NM Assignment EE-20309

Backward Interpolation Code:


X = input('Enter list of abscissas: ');
Y = input('Enter list of ordinates: ');
p0= input('Enter point of approximation: ');
n = length(X);
h = X(2) - X(1);
B = zeros(n,n);
B(:,1) = Y;
for j=2:n
for i=1:n-j+1
B(i,j) = B(i+1,j-1) - B(i,j-1);
end
end
B
C= B(1,n);
for k=n-1:-1:1
p = poly(X(n))/h;
p(2) = p(2) + (k-1);
C = conv(C,p)/k;
m= length(C);
C(m) = C(m) + B(n-k+1,k);
end
A= polyval(C,p0);
fprintf('Approximate value at given data point is : %4f\n',A);
x=linspace (X(1),X(n),100);
y=polyval(C,x);
plot(x,y,'r')
hold on
plot(X,Y,'o')

Result:
Sadaf Saeed NM Assignment EE-20309

Forward Interpolation Code:


X=input('Enter list of abscissas: ');
Y=input('Enter list of ordinates: ');
p0=input('Enter point of approxiamation: ');
n= length (X);
h= X(2)- X(1);
F= zeros(n,n);
F(:,1) = Y;
for j=2:n
for i=j:n
F(i,j)=F(i,j-1) - F(i-1,j-1);
end
end
F
C= F(n,n);
for k=n-1:-1:1
p = poly(X(1))/h;
p(2) = p(2) - (k-1);
C = conv(C,p)/k;
m= length(C);
C(m) = C(m) + F(k,k);
end

A= polyval(C,p0);
fprintf('Approximate value at given data point is : %4f\n',A);
x=linspace (X(1),X(n),100);
y=polyval(C,x);
plot(x,y,'r')
hold on
plot(X,Y,'o')

Result:

You might also like