function [y1,n]=Dichotomie(x0,x1,nmax,eps)
  a=x0
  b=x1
  y1=a
   deff('y=f(x)','y=x^3+2*x^2+10*x-20')
   if (f(a)*f(b)>0) then
     
    halt( 'Conditions initiales non valides ')
  end
   fid=mopen('../../Users/Benjamin//Enseignement/L2/MN1/Dichotomie.dat','w')
  n=0;
  while ((n<nmax)&(abs(f(y1))>eps))
    y1=(a+b)/2
    if (f(a)*f(y1)>0) then
      a=y1
      elseif (f(a)*f(y1)<0) then
      b=y1
    else
      mfprintf(6, 'Algorithme termin� \n')
    end        
      mfprintf(fid,'%f \n',y1)
     n=n+1
   end  
   mclose(fid)
endfunction

function [y,n]=corde(x0,a,b,nmax,eps)
   y=x0;
  fid=mopen('Corde.dat','w')
  deff('y=f(x)','y=x^3+2*x^2+10*x-20')
  n=0;
   while((n<nmax)&(abs(f(y))>eps))
     y=y-(f(y)*(b-a))/(f(b)-f(a))
     mfprintf(fid, '%.20f \n',y)
     n=n+1
   end 
   mclose(fid)
endfunction


function [y,n]=newton(x0,nmax,eps)
 format(20)
  y=x0;
  fid=mopen('Newton.dat','w')
  deff('y=f(x)','y=x^3+2*x^2+10*x-20')
  deff('y=df(x)','y=3*x^2+4*x+10')
  n=0;
   while((n<nmax)&(abs(f(y))>eps))
     y=y-(f(y)/df(y))
     mfprintf(fid, '%.26f \n',y)
     n=n+1
   end 
   mclose(fid) 

  endfunction
  

  
function [y1,n]=Lagrange(x0,x1,nmax,eps)
  y0=x0;
  y1=x1;
   fid=mopen('Lagrange.dat','w')
  deff('y=f(x)','y=x^3+2*x^2+10*x-20')
  n=0;
  while((n<nmax)&(abs(f(y1))>eps))
     a=y1    
     y1=y1-((f(y1)*(y1-y0))/(f(y1)-f(y0)))
     y0=a     
      mfprintf(fid, '%.26f \n',y1)
     n=n+1
   end  
   mclose(fid)
endfunction

function [y1,n]=RegulaFalsi(x0,x1,nmax,eps)
  
  a=x0
  b=x1
  y1=a
   deff('y=f(x)','y=x^3+2*x^2+10*x-20')
   if (f(a)*f(b)>0) then
     
    halt( 'Conditions initiales non valides ')
  end
   fid=mopen('../../Users/Benjamin/Enseignement/L2/MN1/ RegulaFalsi.dat','w')
  n=0;
  while ((n<nmax)&(abs(f(y1))>eps))
    y1=a-((f(a)*(a-b))/(f(a)-f(b)))
    if (f(a)*f(y1)>0) then
      a=y1
    elseif (f(a)*f(y1)<0) then
      b=y1 
    else
      mfprintf(6, 'Algorithme termin� \n')
    end        
      mfprintf(fid, '%f \n',y1)
     n=n+1
   end  
   mclose(fid)
endfunction



   
