# Why the last err is a row vector of all zeros instead of a single zero?

1 view (last 30 days)
Sadiq Akbar on 3 Mar 2024
Commented: Sadiq Akbar on 3 Mar 2024
I want to reduce the number of variables in the following code. Also, the value of the last variable should be a single zero but it gives a row vector of zeros.
clear;clc
u=[1 2 0.1 0.2 3 4 30 40 50 60];
b=[1.1 1.2 0.11 0.21 33 44 31 41 51 61];
a1 = u(1:2);
r1 = u(3:4);
f1 = u(5:6);
theta1 = u(7:8);
phi1 = u(9:10);
fmax1=10;
m=(1:5).';
n=m;
% for b
a2 = b(1:2);
r2 = b(3:4);
f2 = b(5:6);
theta2 = b(7:8);
phi2 = b(9:10);
fmax2=10;
m=(1:5).';
n=m;
xo = sum(a1.*exp(-1i*((pi/fmax1).*(-m.*f1/2).*sind(theta1).*cosd(phi1)+m.^2.*f1.^2./16.*r1).*(1-sind(theta1).^2.*cosd(phi1).^2)),2)
yo = sum(a1.*exp(-1i*((pi/fmax1).*(-n.*f1/2).*sind(theta1).*sind(phi1)+n.^2.*f1.^2./16.*r1).*(1-sind(theta1).^2.*sind(phi1).^2)),2)
xe = sum(a2.*exp(-1i*((pi/fmax2).*(-m.*f2/2).*sind(theta2).*cosd(phi2)+m.^2.*f2.^2./16.*r2).*(1-sind(theta2).^2.*cosd(phi2).^2)),2)
ye = sum(a2.*exp(-1i*((pi/fmax2).*(-n.*f2/2).*sind(theta2).*sind(phi2)+n.^2.*f2.^2./16.*r2).*(1-sind(theta2).^2.*sind(phi2).^2)),2)
%%%%%%%%%%%%%%%%%%
% MSE
%%%%%%%%%%%%%%%%%%
%e=norm(xo-xe).^2/(M);
errx=norm(xo-xe).^2/(m);
erry=norm(yo-ye).^2/(n);
err=errx+erry

VBBV on 3 Mar 2024
clear;clc
u=[1 2 0.1 0.2 3 4 30 40 50 60];
b=[1.1 1.2 0.11 0.21 33 44 31 41 51 61];
a1 = u(1:2);
r1 = u(3:4);
f1 = u(5:6);
theta1 = u(7:8);
phi1 = u(9:10);
fmax1=10;
m=(1:5).';
n=m;
% for b
a2 = b(1:2);
r2 = b(3:4);
f2 = b(5:6);
theta2 = b(7:8);
phi2 = b(9:10);
fmax2=10;
m=(1:5).';
n=m;
xo = sum(a1.*exp(-1i*((pi/fmax1).*(-m.*f1/2).*sind(theta1).*cosd(phi1)+m.^2.*f1.^2./16.*r1).*(1-sind(theta1).^2.*cosd(phi1).^2)),2);
yo = sum(a1.*exp(-1i*((pi/fmax1).*(-n.*f1/2).*sind(theta1).*sind(phi1)+n.^2.*f1.^2./16.*r1).*(1-sind(theta1).^2.*sind(phi1).^2)),2);
xe = sum(a2.*exp(-1i*((pi/fmax2).*(-m.*f2/2).*sind(theta2).*cosd(phi2)+m.^2.*f2.^2./16.*r2).*(1-sind(theta2).^2.*cosd(phi2).^2)),2);
ye = sum(a2.*exp(-1i*((pi/fmax2).*(-n.*f2/2).*sind(theta2).*sind(phi2)+n.^2.*f2.^2./16.*r2).*(1-sind(theta2).^2.*sind(phi2).^2)),2);
%%%%%%%%%%%%%%%%%%
% MSE
%%%%%%%%%%%%%%%%%%
%e=norm(xo-xe).^2/(M);
errx=norm(xo-xe).^2./(m); % do element wise division
erry=norm(yo-ye).^2./(n); % do element wise division
err=errx+erry
err = 5×1
98.1008 49.0504 32.7003 24.5252 19.6202
##### 3 CommentsShow 1 older commentHide 1 older comment
VBBV on 3 Mar 2024
if you want a scalar, use p-norm criterion, however it may not be zero
clear;clc
u=[1 2 0.1 0.2 3 4 30 40 50 60];
b=[1.1 1.2 0.11 0.21 33 44 31 41 51 61];
a1 = u(1:2);
r1 = u(3:4);
f1 = u(5:6);
theta1 = u(7:8);
phi1 = u(9:10);
fmax1=10;
m=(1:5).';
n=m;
% for b
a2 = b(1:2);
r2 = b(3:4);
f2 = b(5:6);
theta2 = b(7:8);
phi2 = b(9:10);
fmax2=10;
m=(1:5).';
n=m;
xo = sum(a1.*exp(-1i*((pi/fmax1).*(-m.*f1/2).*sind(theta1).*cosd(phi1)+m.^2.*f1.^2./16.*r1).*(1-sind(theta1).^2.*cosd(phi1).^2)),2);
yo = sum(a1.*exp(-1i*((pi/fmax1).*(-n.*f1/2).*sind(theta1).*sind(phi1)+n.^2.*f1.^2./16.*r1).*(1-sind(theta1).^2.*sind(phi1).^2)),2);
xe = sum(a2.*exp(-1i*((pi/fmax2).*(-m.*f2/2).*sind(theta2).*cosd(phi2)+m.^2.*f2.^2./16.*r2).*(1-sind(theta2).^2.*cosd(phi2).^2)),2);
ye = sum(a2.*exp(-1i*((pi/fmax2).*(-n.*f2/2).*sind(theta2).*sind(phi2)+n.^2.*f2.^2./16.*r2).*(1-sind(theta2).^2.*sind(phi2).^2)),2);
%%%%%%%%%%%%%%%%%%
% MSE
%%%%%%%%%%%%%%%%%%
%e=norm(xo-xe).^2/(M);
errx=norm((xo-xe).^2./(m)); % do element wise division
erry=norm((yo-ye).^2./(n)); % do element wise division
err=errx+erry
err = 25.0652
Sadiq Akbar on 3 Mar 2024
Thanks a lot for your kind response.