No BSD License
Highlights from
xLOGy
from
xLOGy
by Jasper Menger
Generalized logarithm
|
| xlogy(X, Y)
|
function N = xlogy(X, Y)
% XLOGY - Logarithm
%
% XLOGY(X,Y) returns the N for which X ^ N = Y.
% XLOGY is defined as LOG(Y) elementswise divided by LOG(X).
%
% N is defined as one for all elements where X equals one, and
% also for elements where X and Y are equal.
%
% The log of X = 0 for any Y is defined as Inf.
%
% Jasper Menger, November 2006
% Validate inputs
if nargin < 2
error('Not enough inputs provided');
end
if not(size(X, 1) == size(Y, 1)) | not(size(X, 2) == size(Y, 2))
error('Inputs X and Y should be of equal size');
end
% N is zero until proven otherwise
N = zeros(size(X));
% N for all valid elements (X & Y not one, and X & Y not equal)
Iok = (X ~= 0 & Y ~= 0 & X ~= 1 & Y ~= 1 & X ~= Y);
N(Iok) = log(Y(Iok)) ./ log(X(Iok));
% N equals one where X equals one
Ione = find(X == 1);
N(Ione) = 1;
% N equals infinite where X equals zero
Iinf = find(X == 0);
N(Iinf) = Inf;
% Done!
|
|
Contact us at files@mathworks.com