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.
Show older comments
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 Comments
Geoff Hayes
on 20 Jul 2014
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
on 20 Jul 2014
Accepted Answer
More Answers (0)
Categories
Find more on Code Performance 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!