title: Program an iteration which will be stopped when the mentioned circumstance is met
body: <p>Hi everyone I have encountered a problem in writing a programming code for the algorithm as shown below</p>
  
  <p>This program is going to be terminated when the approximate error which is defined as (current approximation-previous approximation)/current approximation is less than 0.01. It can be simplified as (f(xr)i+1 - f(xr)i)/f(xr)i+1. Below are the code that I have written and I would really like to know how can I program an iteration which will be stopped when the mentioned circumstance is met. </p>
  
  <pre><code>xl = input('Enter lower limit : ');
  
  xu = input('Enter upper limit : ');
  
  xr = (xl+xu)/2;
  
  R = 3; V = 30;
  
  fl = (pi*R*xl^2)-(pi*(xl^3)/3)-V;    % between is there anyway can call these functions 
  
  fu = (pi*R*xu^2)-(pi*(xu^3)/3)-V;      other than typing 3 times
  
  fh = (pi*R*xr^2)-(pi*(xr^3)/3)-V;
  
  
  while relative error is less than 0.01 then display value of xr
  
  if fl*fu&lt;0
  
      xu = xr;
  
  
  elseif fl*fu&gt;0
  
      xl = xr;
  
  
  end
  
  end
  </code></pre>