comparison scripts/polynomial/pchip.m @ 5838:376e02b2ce70

[project @ 2006-06-01 20:23:53 by jwe]
author jwe
date Thu, 01 Jun 2006 20:23:54 +0000
parents 55404f3b0da1
children 98ee80702bca
comparison
equal deleted inserted replaced
5837:55404f3b0da1 5838:376e02b2ce70
89 endif 89 endif
90 else 90 else
91 y = reshape (y, [prod(szy(1:end-1)), szy(end)])'; 91 y = reshape (y, [prod(szy(1:end-1)), szy(end)])';
92 endif 92 endif
93 93
94 h = diff(x); 94 h = diff (x);
95 if all(h<0) 95 if (all (h < 0))
96 x = flipud(x); 96 x = flipud (x);
97 h = diff(x); 97 h = diff (x);
98 y = flipud(y); 98 y = flipud (y);
99 elseif (any(h <= 0)) 99 elseif (any (h <= 0))
100 error("pchip: x must be strictly monotonic") 100 error("pchip: x must be strictly monotonic")
101 endif 101 endif
102 102
103 if (rows(y) != n) 103 if (rows (y) != n)
104 error("pchip: size of x and y must match"); 104 error("pchip: size of x and y must match");
105 endif 105 endif
106 106
107 [ry, cy] = size (y); 107 [ry, cy] = size (y);
108 if (cy > 1) 108 if (cy > 1)
110 endif 110 endif
111 111
112 dy = diff (y) ./ h; 112 dy = diff (y) ./ h;
113 113
114 a = y; 114 a = y;
115 b = __pchip_deriv__(x,y); 115 b = __pchip_deriv__ (x, y);
116 c = - (b(2:n, :) + 2 * b(1:n - 1, :)) ./ h + 3 * diff (a) ./ h .^ 2; 116 c = - (b(2:n, :) + 2 * b(1:n - 1, :)) ./ h + 3 * diff (a) ./ h .^ 2;
117 d = (b(1:n - 1, :) + b(2:n, :)) ./ h.^2 - 2 * diff (a) ./ h.^3; 117 d = (b(1:n - 1, :) + b(2:n, :)) ./ h.^2 - 2 * diff (a) ./ h.^3;
118 118
119 d = d(1:n - 1, :); c = c(1:n - 1, :); 119 d = d(1:n - 1, :); c = c(1:n - 1, :);
120 b = b(1:n - 1, :); a = a(1:n - 1, :); 120 b = b(1:n - 1, :); a = a(1:n - 1, :);