-
Notifications
You must be signed in to change notification settings - Fork 3
/
interp.m
25 lines (25 loc) · 954 Bytes
/
interp.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
%% interp - Program to interpolate data using Lagrange
% polynomial to fit quadratic to three data points
clear all; help interp; % Clear memory and print header
%% * Initialize the data points to be fit by quadratic
disp('Enter data points as x,y pairs (e.g., [1 2])');
for i=1:3
temp = input('Enter data point: ');
x(i) = temp(1);
y(i) = temp(2);
end
%% * Establish the range of interpolation (from x_min to x_max)
xr = input('Enter range of x values as [x_min x_max]: ');
%% * Find yi for the desired interpolation values xi using
% the function intrpf
nplot = 100; % Number of points for interpolation curve
for i=1:nplot
xi(i) = xr(1) + (xr(2)-xr(1))*(i-1)/(nplot-1);
yi(i) = intrpf(xi(i),x,y); % Use intrpf function to interpolate
end
%% * Plot the curve given by (xi,yi) and mark original data points
plot(x,y,'*',xi,yi,'-');
xlabel('x');
ylabel('y');
title('Three point interpolation');
legend('Data points','Interpolation ');