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

1 次查看(过去 30 天)
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
VBBV 2024-3-3
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 个评论
VBBV
VBBV 2024-3-3
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by