Half tanh for x < 0 Input: - x: input value [n,m] Output: - f: function [n,m] - df: first derivative [n,m] - d2f: second derivative [n,m]
0001 function [f,df,d2f] = halftanh(x) 0002 % 0003 % Half tanh for x < 0 0004 % 0005 % Input: 0006 % 0007 % - x: input value [n,m] 0008 % 0009 % Output: 0010 % 0011 % - f: function [n,m] 0012 % - df: first derivative [n,m] 0013 % - d2f: second derivative [n,m] 0014 0015 % 0016 %by Y.PEYSSON CEA-IRFM <yves.peysson@cea.fr> and Joan Decker CEA-IRFM (joan.decker@cea.fr) 0017 % 0018 f = x; 0019 f(x<0) = tanh(x(x<0)); 0020 f(x<-400) = -1; 0021 % 0022 df = ones(size(x)); 0023 df(x<0) = 1.0./cosh(x(x<0))./cosh(x(x<0)); 0024 df(x<-400) = 0; 0025 % 0026 d2f = zeros(size(x)); 0027 d2f(x<0) = -2.0*sinh(x(x<0))./cosh(x(x<0)).^3; 0028 d2f(x<-400) = 0; 0029 % 0030