% ### EXplotTANH.m ### 09.09.16 % Code to plot a hyperbolic tangent [y= tanh(a*x)] via two ways: % o 1. explicit definition (e.g., see % http://mathworld.wolfram.com/HyperbolicTangent.html) % o 2. via Matlab's built-in tanh function (e.g., type "help tanh") clear % ---------------- a= 1.5; % const. appearing in function xSpan= [-5 5]; % domain pts= 50; % # of points to compute function at % ---------------- x= linspace(xSpan(1),xSpan(2),pts); % determine the domain y1= (exp(2*a*x)-1)./(exp(2*a*x)+1); y2= tanh(a*x); figure(1); clf; h1= plot(x,y1,'b-'); hold on; grid on; h2= plot(x,y2,'rx'); xlabel('x'); ylabel('y'); legend([h1 h2],'Explicit definition','Matlabs built-in function','Location','NorthWest'); title('Plotting Hyperbolic tangent');