Is there any way that I can optimise this code. It takes lot of time to run and for larger iteration like 'nc=10e6' its stops stating runtime error.
이전 댓글 표시
clear all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Simulation of transmission signal decay from a high Finesse Fabry-Perot cavity
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%Author-Jayash
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nc=1000000; % no. of cycles inside the cavity
t=1;
Finesse=140000;
%x=-5e4:1:5e4;
ni=1;
f=1/t;
while ni < nc
syms x n r fsr
ESm = symsum((r)^(2*n - 2).*exp(-1i*(x./(2*fsr))*(n - 1)),n,0,ni); % summation of signal(s) to be deducted in each cycle.
R = 0.9999775603; % Reflectivity of cavity mirrors
T = 1 - R;
x = sqrt(R);
r=x;
fsr=10e9;
Itn=1./(1+(Finesse.*((sin(f./(2*fsr)))^2))); % Transmission Intensity from Cavity
ESe = T.*ESm;
ISe = ESe.*conj(ESe);
Itn1=Itn-ISe; % Decay in each cycle
%plot(Itn1,t);
plot(t,double(subs(Itn1)),'*');
hold on
ns=ni+10000;
ni=ns;
t=t+ni.*(10e-9);
end
댓글 수: 2
Geoff Hayes
2014년 7월 20일
When you say that it takes a lot of time to run, what exactly does that mean? More than a few minutes, hours, more?
When nc=1000000, you say that its stops stating runtime error? Please include the full error message that you observe.
Note that there are a couple of errors in the above code
fsr=
if true
% code
end10e9;
What should fsr be initialized to? Why is there a 10e9?
The code
ns=ni+10000;
ni=ns;
can be replaced by
ni = ni + 10000;
jayash
2014년 7월 20일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Code Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!