It works, it has a help text (but not at the usual location) and some comments, but no H1-line.
Mathematically, the algorithm is weak: The formula is calculated at 1000 equidistant steps of the allowed interval. Then one point with the smalles difference to the wanted value is picked out and the new interval is limited to the mean of this point and the old interval limits. The check of reaching the goal does not consider a tolerance, but checks for equality.
This strategy can fail e.g. for periodical values (SIN, COS) and the choice of the new limits is more or less arbitrary. There are much better methods to find a solution of the function F(x) - y = 0, e.g. Matlab's FZERO, FMINBND. Using the processing time as termination criterion effects a randomness of the result, especially if TIC/TOC is used to measure the time: The result depends on the procesor speed and the activity of background processes! The number of iterations is better to create reproducible results.
Using anonymous functions or function handles as input is better than defining the function as string and replacing all 'N' - what will happen for the function 'mySIN(N)' ?!
It works, it has a help text (but not at the usual location) and some comments, but no H1-line.
Mathematically, the algorithm is weak: The formula is calculated at 1000 equidistant steps of the allowed interval. Then one point with the smalles difference to the wanted value is picked out and the new interval is limited to the mean of this point and the old interval limits. The check of reaching the goal does not consider a tolerance, but checks for equality.
This strategy can fail e.g. for periodical values (SIN, COS) and the choice of the new limits is more or less arbitrary. There are much better methods to find a solution of the function F(x) - y = 0, e.g. Matlab's FZERO, FMINBND. Using the processing time as termination criterion effects a randomness of the result, especially if TIC/TOC is used to measure the time: The result depends on the procesor speed and the activity of background processes! The number of iterations is better to create reproducible results.
Using anonymous functions or function handles as input is better than defining the function as string and replacing all 'N' - what will happen for the function 'mySIN(N)' ?!