Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [ fcos ] = cosine( x, n )
- %Cosine Provides the cosine (cos x) of the input
- % cosine(x) takes a matrices of values (in radians) and outputs a
- % matrices containing an approximate cosine of each value in the matrix.
- %
- % cosine(x) takes a matrices 'x' and returns the cosines. Tbe default
- % number of values in the series is 10.
- % cosine(x) takes a matrices 'x' and 'n', the number of values in the
- % series, and returns a matrices of the cosines of 'x'.
- if (nargin < 2) || isempty(n)
- n = 10;
- end
- validateattributes(x, {'numeric'}, {'finite', 'real', 'finite'});
- validateattributes(n, {'numeric'}, {'integer', 'scalar', 'finite', 'positive'});
- [columns, rows] = size(x);
- fcos = zeros(columns,rows);
- for i = 1:numel(x)
- fcos(i) = (sum(((-1).^(0:n)).*(x(i).^(2*(0:n)))./(factorial(2*(0:n)))));
- end
- if numel(fcos)~=numel(x)
- error('cosine:inputoutputmismatch','The output matrix is smaller than the input matrix')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement