how to reduce its computing time?

1 view (last 30 days)
Sadiq Akbar
Sadiq Akbar on 31 Dec 2022
Commented: Sadiq Akbar on 31 Dec 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);

Accepted Answer

Torsten
Torsten on 31 Dec 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 Comments
Torsten
Torsten on 31 Dec 2022
Edited: Torsten on 31 Dec 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 on 31 Dec 2022
Thanks a lot dear Torsten for your help.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!