forked from chebfun/chebfun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
poly.m
34 lines (30 loc) · 1.29 KB
/
poly.m
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
function out = poly(f)
%POLY Polynomial coefficients of a TRIGTECH.
% C = POLY(F) returns the polynomial coefficients of F so that:
% If N is odd
% F(x) = C(1)*z^(N-1)/2 + C(2)*z^((N-1)/2-1) + ... + C(N)*z^(-(N-1)/2)
% If N is even
% F(x) = C(1)*z^(N/2-1) + C(2)*z^(N/2-2) + ... + C(N-1)*z^(-N/2-1) +
% 1/2*C(N)*(z^(N/2) + z^(-N/2))
% where z = exp(1i*pi*x) and -1 <= x <= 1.
%
% Note that unlike the MATLAB POLY command, TRIGTECH/POLY can operate on
% array-valued TRIGTECH objects, and hence produce a matrix output. In such
% instances, the rows of C correspond to the columns of F = [F1, F2, ...].
% That is, in the case N is odd
% F1(x) = C(1,1)*z^(N-1)/2 + C(1,2)*z^((N-1)/2-1) + ... + C(1,N)*z^(-(N-1)/2)
% F2(x) = C(2,1)*z^(N-1)/2 + C(2,2)*z^((N-1)/2-1) + ... + C(2,N)*z^(-(N-1)/2)
% This strange behaviour is a result of MATLAB's decision to return a row
% vector from the POLY command, even for column vector input.
%
% See also CHEBCOEFFS, TRIGCOEFFS, LEGCOEFFS.
% Copyright 2017 by The University of Oxford and The Chebfun Developers.
% See http://www.chebfun.org/ for Chebfun information.
% Deal with empty case:
if ( isempty(f) )
out = [];
return
end
% Simply return the transpose of the coefficients:
out = f.coeffs.';
end