MATLAB Answers

How do I make a function work with vectors?

4 views (last 30 days)
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 Comments

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 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 Comments

Sign in to comment.

More Answers (1)

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

  0 Comments

Sign in to comment.