how to reduce its computing time?

1 vue (au cours des 30 derniers jours)
Sadiq Akbar
Sadiq Akbar le 31 Déc 2022
Commenté : Sadiq Akbar le 31 Déc 2022
u=[30 40 50 70];
b=u;
[~,C]=size(b);
P=C/2;
M=10;
xo=zeros(1,M);
yo=zeros(1,M);
zo=zeros(1,M);
for k=1:M
for i=1:P
xo(1,k)=xo(1,k)+exp(-1i*(k-1)*pi*sind(u(i))*cosd(u(P+i)));
yo(1,k)=yo(1,k)+exp(-1i*(k-1)*pi*sind(u(i))*(cosd(u(P+i))+sind(u(P+i))));
zo(1,k)=zo(1,k)+exp(-1i*(k-1)*pi*sind(u(i))*cosd(u(P+i))+cosd(u(i)));
end %end of i
end
xe=zeros(1,M);
ye=zeros(1,M);
ze=zeros(1,M);
for k=1:M
for i=1:P
xe(1,k)=xe(1,k)+exp(-1i*(k-1)*pi*sind(b(i))*cosd(b(P+i)));
ye(1,k)=ye(1,k)+exp(-1i*(k-1)*pi*sind(b(i))*(cosd(b(P+i))+sind(b(P+i))));
ze(1,k)=ze(1,k)+exp(-1i*(k-1)*pi*sind(b(i))*cosd(b(P+i))+cosd(b(i)));
end %end of i
end %end of k
abc=0.0;
abcd=0.0;
abcde=0.0;
for m1=1:M
abc=abc+(abs(xo(1,m1)-xe(1,m1))).^2;
abcd=abcd+(abs(yo(1,m1)-ye(1,m1))).^2;
abcde=abcde+(abs(zo(1,m1)-ze(1,m1))).^2;
end%end of m1
err=abc+abcd+abcde;
err=err/(3*M);

Réponse acceptée

Torsten
Torsten le 31 Déc 2022
Here is the code for the first loop. You can do it for the other loops in the same manner.
u=[30 40 50 70];
b=u;
[~,C]=size(b);
P=C/2;
M=10;
MM =(0:(M-1)).';
PP=1:P
xo = sum(exp(-1i*MM*pi.*sind(u(PP)).*cosd(u(P+PP))),2).'
yo = sum(exp(-1i*MM*pi.*sind(u(PP)).*(cosd(u(P+PP))+sind(u(P+PP)))),2).'
zo = sum(exp(-1i*MM*pi.*sind(u(PP)).*cosd(u(P+PP))+cosd(u(PP))),2).';
  3 commentaires
Torsten
Torsten le 31 Déc 2022
Modifié(e) : Torsten le 31 Déc 2022
abc = sum(abs(xo-xe).^2);
abcd = sum(abs(yo-ye).^2);
abcde = sum(abs(zo-ze).^2);
err = abc+abcd+abcde;
err = err/(3*M);
Sadiq Akbar
Sadiq Akbar le 31 Déc 2022
Thanks a lot dear Torsten for your help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by