fork download
  1. clc;
  2. clear all;
  3. g=@(x) exp(-x);
  4. a=0;
  5. for i=1:10
  6. r(i)=g(a)
  7. err(i)=abs((a-r(i))/r(i))*100;
  8. a=r(i);
  9. fprintf('Iter: %i APP_root: %.6f Error: %.5f\n',i,r(i),err(i));
  10. if err(i)<0.01
  11. break
  12. end
  13. end
  14.  
Success #stdin #stdout 0.1s 47060KB
stdin
Standard input is empty
stdout
r =  1
Iter: 1 APP_root: 1.000000 Error: 100.00000
r =

   1.00000   0.36788

Iter: 2 APP_root: 0.367879 Error: 171.82818
r =

   1.00000   0.36788   0.69220

Iter: 3 APP_root: 0.692201 Error: 46.85364
r =

   1.00000   0.36788   0.69220   0.50047

Iter: 4 APP_root: 0.500474 Error: 38.30915
r =

   1.00000   0.36788   0.69220   0.50047   0.60624

Iter: 5 APP_root: 0.606244 Error: 17.44679
r =

   1.00000   0.36788   0.69220   0.50047   0.60624   0.54540

Iter: 6 APP_root: 0.545396 Error: 11.15662
r =

   1.00000   0.36788   0.69220   0.50047   0.60624   0.54540   0.57961

Iter: 7 APP_root: 0.579612 Error: 5.90335
r =

   1.00000   0.36788   0.69220   0.50047   0.60624   0.54540   0.57961   0.56012

Iter: 8 APP_root: 0.560115 Error: 3.48087
r =

 Columns 1 through 8:

   1.00000   0.36788   0.69220   0.50047   0.60624   0.54540   0.57961   0.56012

 Column 9:

   0.57114

Iter: 9 APP_root: 0.571143 Error: 1.93080
r =

 Columns 1 through 8:

   1.00000   0.36788   0.69220   0.50047   0.60624   0.54540   0.57961   0.56012

 Columns 9 and 10:

   0.57114   0.56488

Iter: 10 APP_root: 0.564879 Error: 1.10887