Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
Aash
Aash am 16 Okt. 2017
Kommentiert: KSSV am 16 Okt. 2017
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)

Akzeptierte Antwort

KSSV
KSSV am 16 Okt. 2017
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)
  2 Kommentare
Aash
Aash am 16 Okt. 2017
thanks very much for your quick help
KSSV
KSSV am 16 Okt. 2017
Thanks is accepting the answer....:)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Simulink Environment Customization finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by