createExitMsg - Fsolve execution Time

2 次查看(过去 30 天)
Brandon
Brandon 2014-11-23
评论: Brandon 2014-11-25
There is a function being called by fsolve called "createExitMsg." I am not using the exit information for anything. Is there anyway I can prevent fsolve from calling this function to save time. My function DetermineSumAlpha is going to be called several thousands of times, so I would love to get my execution time down the best I can.
I've tried commenting out these lines of code in MATLAB, but since it is an internal function I am getting an access denied error.

回答(2 个)

Matt J
Matt J 2014-11-23
编辑:Matt J 2014-11-23
Try turning the 'Display' option to 'off'.
  1 个评论
Matt J
Matt J 2014-11-24
Brandon Commented:
Display options are currently set to off:
persistent options
if isempty(options)
options=optimset('Display','off', 'Jacobian','on', 'TolFun', 1E-3, 'TolX', 1E-3);
else
% Already set, do nothing
end
% options=optimset('Display','on');
% Solve for Theta
Theata = fsolve(@FindTheta, Theta0(1:2), options);
When I turn the display options to "on" it takes approximately 0.7 seconds to createExitMsg. It appears that fsolve calls createExitMsg even if display is set to of and only displays the message when it is set to on.

请先登录,再进行评论。


Matt J
Matt J 2014-11-23
编辑:Matt J 2014-11-23
My function DetermineSumAlpha is going to be called several thousands of times
If you are calling fsolve several thousand times, you should try to combine the thousands of equations into a single system so that you only have to call fsolve once (or fewer times). That way, service and set-up operations like createExitMsg are only done once and don't dominate the execution time.
  3 个评论
Matt J
Matt J 2014-11-24
编辑:Matt J 2014-11-24
Correct me if I am wrong, but my thoughts are that the convergence rate increase exponentially as the size of the system increases.
Not if there's no coupling between the systems. Since the Jacobian is then block diagonal, variables in each system get updated just the same as if you had solved each system separately. You can also use the JacobPattern option (if using the Trust-Region Reflective algorithm) to tell the code that the Jacobian is sparse and block diagonal, or supply your own sparse Jacobian calculation in whatever algorithm you're running.
Brandon
Brandon 2014-11-25
I am defining a custom jacobian matrix, so that is being determined analytically rather than through finite difference methods. I have already gone through several of the solvers and determined that the default solver is providing the best results in terms of time.
I am not able to solve all of the equations simultaneous for all 200 cases because each set of equations has the potential of up to 4 solutions. I am using the results of the previous iteration as an initial guess into the next solution to guarantee that I am converging on the correct one.
I've since switched to a more powerful computer with a newer version of MATLAB. I've gotten a considerable increase in speed just from that.
I guess that will do.
Thanks

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by