I want to solve an implicit equation (dispersion equation) around 100000 times. At the beginning of the calculations the script goes fast but little by little it goes slower and slower. I suppose the problem lies on the for loop, but i do not know how to optimize the script. Any help is appreciated!
% Te is data
fidw=fopen('Longitud','wt');
n=length(Te);
syms L0
d=53; %depth
pi=3.1416;
for i=1:n;
L=solve(L0-(9.81*Te(i)^2/(2*pi))*tanh((2*pi/L0)*d));
end
L=double(L);
L=abs(L);
vector_L=L;
fprintf(fidw,'%03.1f\n',vector_L(i));
fclose(fidw);