Why the last err is a row vector of all zeros instead of a single zero?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
VBBV
il 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
3 Commenti
VBBV
il 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
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Parametric Spectral Estimation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!