trying to find L2 norm using for loops. where am I doing wrong?

1 次查看(过去 30 天)
clear all
clearvars
x = [1.21, -3.42, 10.01, -0.13, -5.11, -1.29, 3.87, 2.16, -3.21, 0.02]
n = length(x)
sumx = 0
for x = 1: n
sumx = sum + [x(n)^2]
end
L2 = sqrt(sumx)

采纳的回答

KSSV
KSSV 2017-10-16
x = [1.21, -3.42, 10.01, -0.13, -5.11, -1.29, 3.87, 2.16, -3.21, 0.02] ;
n = length(x) ;
sumx = 0 ;
for i = 1: n
sumx = sumx + x(i)^2 ;
end
L2 = sqrt(sumx)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Environment Customization 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by