Help me make this small inner loop faster - more efficient notation or functions?
Mostrar comentarios más antiguos
I have some code which runs this inner loop a LOT of times for different values of Ri and Ii:
z = complex(Ri,Ii);
for (k=1:50)
e1 = eval(formula);
e2 = eval(derivative);
z = z - e1/e2 / (1 - (e1*eval(derivative2))/(2*power(e2,2.0)));
g = power(real(z),2)+power(imag(z),2);
if (k>1 && abs(g-gprev)<epsilon)
break;
end
gprev = g;
end
Formula is a string expression involving "z" (input by user at run-time, so can't be hardcoded) and derivative is it's symbolic derivative. I know eval() is supposed to be subs() but that seems to make it way slower. Is there anything I should be doing in terms of choosing better functions or notation that would help speed this up?
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Function Creation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!