Borrar filtros
Borrar filtros

How to create this function in Matlab?

2 visualizaciones (últimos 30 días)
vish
vish el 25 de Mzo. de 2011
I want to write a mathematical function in matlab so that I can call it in my program whenever needed.
? a(n).b(n)/sqrt((a(n)^2) + (b(n)^2))
n=0 to limit. The limit is approx 1000.
a and b are 1 dimensional matrix. size of a and b is : (1xlimit)
  6 comentarios
Matt Fig
Matt Fig el 26 de Mzo. de 2011
Did you try the codes below?
vish
vish el 26 de Mzo. de 2011
Thanks, I just tried it. Its working. Matlabs really powerful. I am grateful for showing me the snippet.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 25 de Mzo. de 2011
Assuming the '?' is the summation operator, then:
sum(a.*b./sqrt(a.^2 + b.^2))
  1 comentario
Matt Fig
Matt Fig el 25 de Mzo. de 2011
Beat me too it! I was too slow deciphering the question, I guess.

Iniciar sesión para comentar.

Más respuestas (1)

Matt Fig
Matt Fig el 25 de Mzo. de 2011
If I understand you correctly,
function S = mysum(a,b)
S = sum(a.*b./sqrt(a.^2 + b.^2));
EDIT
.
. Sean de points out known stability issues with square roots of the sum of squares.
function S = mysum(a,b)
S = sum(a.*b./hypot(a,b));
  2 comentarios
Sean de Wolski
Sean de Wolski el 25 de Mzo. de 2011
I would use:
./hypot(a,b)
Matt Fig
Matt Fig el 25 de Mzo. de 2011
That too...

Iniciar sesión para comentar.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by