Steelierelk - I suspect that the
"Undefined function or variable 'r'"
corresponds to the
line. If this is true, then this is because whatever inputs you have entered are such that the while loop condition
evaluates to false...and so the r variable never gets set. I would set a breakpoint at this line (the while condition) and verify that the values you have passed into this function make sense given the condition.
It is also good practice to assign default values to output variables so that at least something is assigned to them.
And, what do you mean by you evaluated the line xr=(xl+xu)/2. When did you evaluate this? After you had run the function (in which case the variables would be out of scope and so be undefined)? Or were you stepping through the code with the debugger?