-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcubic_hermite_spline.lib.gnu
More file actions
44 lines (33 loc) · 1.59 KB
/
cubic_hermite_spline.lib.gnu
File metadata and controls
44 lines (33 loc) · 1.59 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
# Alessandro Corbetta, 2019
## USAGE:
# cubHerMulti3t(x0,u0,x1,u1,x2,u2,t)
#
# where x0,u0 are the value and the
# derivative at t=0, x1,u1 are the value and first derivative at t=1
# and so on
#basis functions, as in http://gnuplot.sourceforge.net/demo/spline.html
h00(x) = x**2 * ( 2 * x - 3) + 1
h01(x) = -x**2 * (2 * x - 3)
h10(x) = x * (x - 1)**2
h11(x) = x**2 * (x - 1)
## combination weights can be overridden if necessary, otherwise they are defaulted to 0.4
if (!exists("GPFUN_wu0")){
wu0 = .4
}
if (!exists("GPFUN_wu1")){
wu1 = .4
}
#basic definition
cubHer(x0,x1,u0,u1,t) = ((t>=0)&&(t<=1))? h00(t) * x0 + h01(t) * x1 + h10(t) * u0 * wu0 + h11(t) * u1 * wu1 : 0
#bounds a value v between two time instants.
tlim(v,t,tm,tM) = ((t>=tm)&&(t<=tM))? v : 1/0
#sort of recursive construction, note, the next one with time bounding should rather be used.
cubHerMulti2(x0,u0,x1,u1,t) = cubHer(x0,x1,u0,u1,t)
cubHerMulti3(x0,u0,x1,u1,x2,u2,t) = cubHerMulti2(x0,u0,x1,u1,t) + cubHerMulti2(x1,u1,x2,u2,t-1)
cubHerMulti4(x0,u0,x1,u1,x2,u2,x3,u3,t) = cubHerMulti3(x0,u0,x1,u1,x2,u2,t) + cubHerMulti2(x2,u2,x3,u3,t-2)
cubHerMulti5(x0,u0,x1,u1,x2,u2,x3,u3,x4,u4,t) = cubHerMulti4(x0,u0,x1,u1,x2,u2,x3,u3,t) + cubHerMulti2(x3,u3,x4,u4,t-3)
#final hermite polynomials.
cubHerMulti2t(x0,u0,x1,u1,t) = tlim(cubHerMulti2(x0,u0,x1,u1,t),t,0,1)
cubHerMulti3t(x0,u0,x1,u1,x2,u2,t) = tlim(cubHerMulti3(x0,u0,x1,u1,x2,u2,t),t,0,2)
cubHerMulti4t(x0,u0,x1,u1,x2,u2,x3,u3,t) = tlim(cubHerMulti4(x0,u0,x1,u1,x2,u2,x3,u3,t),t,0,3)
cubHerMulti5t(x0,u0,x1,u1,x2,u2,x3,u3,x4,u4,t) = tlim(cubHerMulti5(x0,u0,x1,u1,x2,u2,x3,u3,x4,u4,t),t,0,4)