How to create this function in Matlab?
1 次查看(过去 30 天)
显示 更早的评论
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)
采纳的回答
Walter Roberson
2011-3-25
Assuming the '?' is the summation operator, then:
sum(a.*b./sqrt(a.^2 + b.^2))
1 个评论
更多回答(1 个)
Matt Fig
2011-3-25
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));
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!