2

does anyone here got an idea what is the command that i should use in MATLAB to determine the total computer time taken to run the Nelder-Mead algorithm using FMINSEARCH until it stop. TQ

Shurmajee
  • 1,027
  • 3
  • 12
  • 35

4 Answers4

3

First, you can check the computation time by using the tic/toc instructions. For example:

tic
x = fminsearch('x^2+x+2',10)
toc

Second,the Nelder-Mead algorithm is an Unconstrained Nonlinear Optimization Algorithm that goes iteratively towards the minimum in a heuristic way. From my point of view, it could be slower and not finding a 'good' minima. Thus, I would suggest you to use Quasi-Newton methods, like BFGS. You just need to use the function fminunc.

tashuhka
  • 5,028
  • 4
  • 45
  • 64
1

If you want to time a specific piece of code, you can use

tic
% yourcode
toc

If you cannot edit the code or want to check the total runtime for a function, try

help profile
Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122
0

The code:

t=cputime; 
your_operation; 
cputime-t

returns computational (CPU) time which was spend by your processes. Tic/toc commands return elapsed running time; this may depend on other programmes, which are using the CPU at the same time.

Tomas
  • 335
  • 2
  • 3
  • 10
0

From this answer, the function timeit is preferred to using tic & toc due to internal operations in timeit that account for MATLAB nuances.

According to the documentation,

timeit calls the specified function multiple times, and computes the median of the measurements.

Consider the example taken from the documentation for fminsearch.

% MATLAB R2022a
fun = @(x)100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
x0 = [-1.2,1];
[x,fval] = fminsearch(fun,x0);

RunTime = timeit(@() fminsearch(fun,x0));      % median runtime in seconds
SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41