How do I make a function work with vectors?

3 次查看(过去 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.

采纳的回答

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)))

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by