how to reduce its computing time?

1 次查看(过去 30 天)
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);

采纳的回答

Torsten
Torsten 2022-12-31
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 个评论
Torsten
Torsten 2022-12-31
编辑:Torsten 2022-12-31
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 2022-12-31
Thanks a lot dear Torsten for your help.

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by