summaryrefslogtreecommitdiff
path: root/macros/cheb.sci
diff options
context:
space:
mode:
Diffstat (limited to 'macros/cheb.sci')
-rw-r--r--macros/cheb.sci61
1 files changed, 30 insertions, 31 deletions
diff --git a/macros/cheb.sci b/macros/cheb.sci
index db2df85..1ebf3a0 100644
--- a/macros/cheb.sci
+++ b/macros/cheb.sci
@@ -1,34 +1,33 @@
-function res = cheb (n, x)
-//Calculates the nth-order Chebyshev polynomial at the point x.
-//Calling Sequence
-//cheb(n, x)
-//Parameters
-//n: Filter order
-//x: Point at which the Chebyshev polynomial is calculater.
-//Description
-//This is an Octave function.
-//Equation for Chebyshev polynomial is
-// / cos(n acos(x), |x| <= 1
-// Tn(x) = |
-// \ cosh(n acosh(x), |x| > 1
-//
-//x can also be a vector. In that case the output will also be a vector of same size as x.
-//Examples
-//x = [1 2 3 4]
-// cheb(10, x)
-//ans =
-//
-// 1.0000e+00 2.6209e+05 2.2620e+07 4.5747e+08
+function T = cheb (n, x)
-funcprot(0);
-rhs = argn(2)
-if (rhs < 2 | rhs > 2)
-error("Wrong number of input arguments.")
-end
+ funcprot(0);
+ rhs= argn(2);
+
+ if (rhs ~= 2)
+ error("Wrong Number of input arguments");
+ elseif (~(isscalar (n) & (n == round(n)) & (n >= 0)))
+ error ("cheb: n has to be a positive integer");
+ end
+
+ if (max(size(x)) == 0)
+ T = [];
+ end
+ // avoid resizing latencies
+ T = zeros(size(x));
+ ind = (abs (x) <= 1);
+ if (max(size(ind)))
+ T(ind) = cos(n*acos(x(ind)));
+ end
+
+ ind = abs (x) > 1;
+ if (max(size(ind)))
+ T(ind) = cosh(n*acosh(x(ind)));
+ end
+
+ T = real(T);
+
+ if(size(x)==[1 1])
+ T=T(1);
+ end
-select(rhs)
-
- case 2 then
- res = callOctave("cheb",n,x)
- end
endfunction