-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterpolationOfFuction_g_of_and_f_of
More file actions
56 lines (51 loc) · 1.49 KB
/
Copy pathInterpolationOfFuction_g_of_and_f_of
File metadata and controls
56 lines (51 loc) · 1.49 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
clear all
%% solved by Ranga Teja(25 Feb 2020) Discussion: Kushpal Yadhav, Prof. Mohan Joshi
tolerance = 10^-80;
syms N;
eqn = log(1/tolerance)== log(2^N)+(N+1)*log(N+1)-(N+1); %used striling approximation for factorial solving
degree = double(solve(eqn,N));
n = round(degree+1); % No.of interpolating points
%% finding interpolating points from chebyshev formulation
for k = 1:n
x(k) = cos(((2*(k-1)+1)*pi)/(2*(n+1)));
g_x(k) = g_of(x(k));
end
%% To find the finite difference table call function fin_differ_table
fdt1 = fin_differ_table(n,x,g_x);
%% interpolating polynomial equation generation ( logic borrowed from Kusphal Yadhav)
syms X;
pn_x1 = fdt1(1,2);
product = X-fdt1(1,1);
for i = 3:n+1
pn_x1 = pn_x1 + product*fdt1(1,i);
product = product*(X-fdt1(i-1,1));
end
%% plot comparisons
%give function directly
x_general = -1:0.00001:1;
for i = 1:200001
g_x_general(i) = g_of(x_general(i));
end
figure(1);
plot(x_general,g_x_general)
%x points generated equidistantly from [-1,1]
x_equidistant = linspace(-1,1,n);
for i = 1:n
g_x_equidistant(i) = g_of(x_equidistant(i));
end
fdt2 = fin_differ_table(n,x_equidistant,g_x_equidistant);
syms X;
pn_x2 = fdt2(1,2);
product = X-fdt2(1,1);
for i = 3:n+1
pn_x2 = pn_x2 + product*fdt2(1,i);
product = product*(X-fdt2(i-1,1));
end
g_x_equi = double(subs(pn_x2,X,x_equidistant));
figure(2);
plot(x_equidistant,g_x_equi)
% x points from chebyshev approximation
x;
g_x_chebyshev = double(subs(pn_x1,X,x));
figure(3);
plot(x,g_x_chebyshev)