How do I make a function work with vectors?

2 visualizaciones (últimos 30 días)
Frandos Castleback
Frandos Castleback el 3 de Abr. de 2020
Respondida: James Tursa el 3 de Abr. de 2020
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.

Respuesta aceptada

James Tursa
James Tursa el 3 de Abr. de 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)))

Más respuestas (1)

Torsten
Torsten el 3 de Abr. de 2020
tanH = (exp(x)-exp(-x))./(exp(x)+exp(-x))

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by