MATLAB: How to calculate number of function evaluation used

Hi guys, can some one help me to solve my problem?
i've be facing difficulty to find the number of function evaluation. let's say that i have f(x)=x^3+x^2-2 with initial value of x(0)=1.5
i want to calculate x(n+1)=x(n)-(f(x(n)/fprime(x(n))) until n=5
thus, i want to calculate how many time of f(x(n)) have been use until n=5. but if the first iteration has use f(x(1)) then the second iteration also use f(x(1)), it is considered as we only use f(x(1)) one time only.
can someone help me

Best Answer

If you're using release R2017a or later you could use memoizedFunction. Once you've used memoizedFunction to solve the problem, call stats on it to determine how many times and with which inputs it was called.