MATLAB Answers

How do I make a function work with vectors?

4 ビュー (過去 30 日間)
Frandos Castleback
Frandos Castleback 2020 年 4 月 3 日
回答済み: James Tursa 2020 年 4 月 3 日
I have this function
function tanH = TAN(x)
tanH(x)=((exp(x))-(exp(-x)))/((exp(x))+(exp(-x)))
end
and I need to change it so that I can get answers if x would be a vector. I've tried putting dots but can't get it to work. What should i be doing?
Thanks in advance.

  0 件のコメント

Sign in to comment.

採用された回答

James Tursa
James Tursa 2020 年 4 月 3 日
Use element-wise divide operator ./ (with the dot) instead of the matrix divide operator / (without the dot). E.g.,
tanH(x)=((exp(x))-(exp(-x)))./((exp(x))+(exp(-x)))

  0 件のコメント

Sign in to comment.

その他の回答 (1 件)

Torsten
Torsten 2020 年 4 月 3 日
tanH = (exp(x)-exp(-x))./(exp(x)+exp(-x))

  0 件のコメント

Sign in to comment.

タグ


Translated by