如何使用for循环将双曲函数(sinh,cosh,tanh)绘制到matlab中的相同图形/图形中?

时间:2013-10-25 06:34:09

标签: matlab function loops plot figure

到目前为止,这是我的代码所用的内容,但图表根本没有出现。

`clear;
clc;
close all;

for a = -2:1:2;
    y = -1:.1:1;
    cosh(a);
    sinh(a);
    tanh(a);
end

plot(a,sinh(a),a,cosh(a),a,tanh(a));`

1 个答案:

答案 0 :(得分:4)

几个问题:

  1. 当您在for循环中运行cosh(a);时,您没有保存该值。
  2. 无论如何都不需要循环,因为cosh等采用矢量输入
  3. y未使用。
  4. 就绘图而言,你可以像这样绘制多个x,y系列,但是在循环之后,a只是一个标量,所以这不会绘制任何有用的东西。
  5. 只需:a = -2:2; plot(a,sinh(a),a,cosh(a),a,tanh(a));