フィルターのクリア

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

2 ビュー (過去 30 日間)
Sadiq Akbar
Sadiq Akbar 2024 年 3 月 3 日
コメント済み: Sadiq Akbar 2024 年 3 月 3 日
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 Center および File ExchangeParametric Spectral Estimation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by