i have vector x = [x_1 x_2 ... x_n], vector y = [y_1 y_2 y_3] , matrix x = [x_11 x_12 ... x_1n; x_21 x_22 ... x_2n; x_31 x_32 ... x_3n].
for i = 1, 2, ..., n, want compute following sum in matlab:
sum((x(i) - y*x(:,i))^2) what have tried write following matlab code:
vv = (x(1) - y*x(:,1))^2; % initialization i=1 = 2 : n vv = vv + (x(i) - y * x(:,i))^2 end but wondering if can compute without loop in order potentially reduce computational time if n high... there other more optimal possibilities in matlab?
any appreciated!
you not need loop @ all,
= 2:n y*x(:,i) end is same y*x, x(i) - yx(:,i) x - yx basically, its:
vv = sum((x - y * x).^2); thanks @beaker pointing mistake.
Comments
Post a Comment