Professional Documents
Culture Documents
Course No Experiment No Name of The Experiment
Course No Experiment No Name of The Experiment
Experiment No: 03
Name of the experiment:
INTERPOLATION
Department: EEE
Level 2 / Term 2
Section: B ( B-2 )
Partners ID: 1206121
Group No:15
EXERCISE 2 Plot the curve corresponding to the following table using linear
Interpolation.
x
0
1
2
3
4
5
6
f(x)
0
0.8415
0.9093
0.1411
-0.7568
-0.9589
-0.2794
Solution
% given data points
x = [0 1 2 3 4 5 6];
y = [0 0.8415 0.9093 0.1411 -0.7568 -0.9589 -0.2794];
plot(x,y,'ko'), hold;
for i=1:length(x)-1
X(1) = x(i);
X(2) = x(i+1);
sum = poly(x(i+1))*y(i)/(x(i)-x(i+1)) poly(x(i))*y(i+1)/(x(i)-x(i+1));
end
EXERCISE 3
y = sin x; x = 0:10, x = 0:0.25:10; construct the interpolant y and plot.
Solution
clear all;
close
all; clc;
% creating
the
data
points
from
given
function. x1 = 0:10;
x2 = 0:0.25:10;
y1 = sin(x1);
y2 = sin(x2);
sum1 = poly(x1(i+1))*y1(i)/(x1(i)-x1(i+1))
- poly(x1(i))*y1(i+1)/(x1(i)-x1(i+1));
p1=polyval(sum1, X1);
subplot(2,1,1), plot(X1,p1), title('Linear Interpolation for x
= 0:10'), grid on, hold on;
end
p2=polyval(sum2, X2);
subplot(2,1,2), plot(X2,p2), title('Linear Interpolation for x
= 0:0.25:10'), grid on, hold on;
end
Plot: