-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathManual_3D_interpolation.jl
More file actions
51 lines (41 loc) · 1.11 KB
/
Manual_3D_interpolation.jl
File metadata and controls
51 lines (41 loc) · 1.11 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
######
# This example shows how to do function approximation in 2D using Padua points
# and in 3D by hand
######
using ApproxFun
import ApproxFun: transform
f = (x,y) -> exp(x*y)
S = Chebyshev(0..1)^2
N = 10^2; p = points(S, N) # 105 padua points
f̃ = (xy) -> f(xy[1], xy[2])
F = f̃.(p)
F̌ = transform(S, F) # 105 Chebyshev^2 coefficients ordered by polynomial degree
f̌ = Fun(S, F̌)
f̌(0.1,0.2) ≈ f(0.1,0.2)
S = Chebyshev(0..1)
p_x = points(S, 10)
p_y = points(S, 10)'
p_z = reshape(points(S, 10), 1, 1, 10)
f = (x,y,z) -> exp(x*y+z)
F = f.(p_x, p_y, p_z)
for k = 1:size(F,2),j=1:size(F,3)
F[:,k,j] = transform(S,F[:,k,j])
end
for k = 1:size(F,1),j=1:size(F,3)
F[k,:,j] = transform(S,F[k,:,j])
end
for k = 1:size(F,1),j=1:size(F,2)
F[k,j,:] = transform(S,F[k,j,:])
end
f̌ = function(x,y,z)
ret1 = Array{Float64}(undef, size(F,2), size(F,3))
for j=1:size(F,2),l=1:size(F,3)
ret1[j,l] = Fun(S,F[:,j,l])(x)
end
ret2 = Array{Float64}(undef, size(F,3))
for l=1:size(F,3)
ret2[l] = Fun(S,ret1[:,l])(y)
end
Fun(S, ret2)(z)
end
f̌(0.1,0.2,0.3) ≈ f(0.1,0.2,0.3)