Help me make this small inner loop faster - more efficient notation or functions?
显示 更早的评论
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?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!