필터 지우기
필터 지우기

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

조회 수: 2 (최근 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
Sadiq Akbar
Sadiq Akbar 2024년 3월 3일
Thanks a lot for your kind response.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Parametric Spectral Estimation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by