How to create this function in Matlab?
Mostrar comentarios más antiguos
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
el 25 de Mzo. de 2011
What is this: a(n).b(n)
is that supposed to be: a(n)*b(n)
Walter Roberson
el 25 de Mzo. de 2011
Is the '?' the summation operator?
vish
el 26 de Mzo. de 2011
vish
el 26 de Mzo. de 2011
Matt Fig
el 26 de Mzo. de 2011
Did you try the codes below?
vish
el 26 de Mzo. de 2011
Respuesta aceptada
Más respuestas (1)
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
el 25 de Mzo. de 2011
I would use:
./hypot(a,b)
Matt Fig
el 25 de Mzo. de 2011
That too...
Categorías
Más información sobre Common Operations en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!