第二,输入以下代码,绘制双曲正切函数tanh、双曲余切函数coth的图像。
close all; clear all; clc
x = -pi:0.5:pi;
y_tanh = tanh(x); % 双曲正切函数
y_coth = coth(x); % 双曲余切函数
figure(1);plot(x,y_tanh,'r-','LineWidth',3);legend('tanh');
line([-pi,pi],[1,1]);line([-pi,pi],[-1,-1]);axis([-pi,pi,-2,2]);
figure(2);plot(x,y_coth,'g-','LineWidth',3);legend('coth');
line([-pi,pi],[1,1]);line([-pi,pi],[-1,-1]);axis([-pi,pi,-10,10]);
figure(3);
plot(x,y_tanh,'r-','LineWidth',3);hold on
plot(x,y_coth,'g-','LineWidth',3);hold off
legend('tanh','coth');
line([-pi,pi],[1,1]);line([-pi,pi],[-1,-1]);
axis([-pi,pi,-10,10]);
xlabel('x');ylabel('y');