MATLAB Answers

How do I make a function work with vectors?

조회 수: 10(최근 30일)
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

댓글을 달려면 로그인하십시오.

채택된 답변

James Tursa
James Tursa 3 Apr 2020
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

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Torsten
Torsten 3 Apr 2020
tanH = (exp(x)-exp(-x))./(exp(x)+exp(-x))

  댓글 수: 0

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by