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);
0 件のコメント
採用された回答
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).';
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!