How to create this function in Matlab?
Ältere Kommentare anzeigen
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)
Akzeptierte Antwort
Weitere Antworten (1)
Matt Fig
am 25 Mär. 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 Kommentare
Sean de Wolski
am 25 Mär. 2011
I would use:
./hypot(a,b)
Matt Fig
am 25 Mär. 2011
That too...
Kategorien
Mehr zu Common Operations finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!