Posted By

CyKy on 12/29/10


Tagged

bisection methodbinarymethod


Versions (?)

Bisection method


 / Published in: C
 

  1. //You can do your own func!
  2.  
  3. float func(float x){
  4. return x-2;
  5. }
  6.  
  7.  
  8. float bisectMeth(float a,float b,float epsilon){
  9. float x=(a+b)/2;
  10. if(func(x)<epsilon && func(x)>=0){
  11. return x;
  12. }else{
  13. if(func(a)*func(x)<0){
  14. return bisectMeth(a,x,epsilon);
  15. }
  16. if(func(b)*func(x)<0){
  17. return bisectMeth(x,b,epsilon);
  18. }
  19. }
  20. }

Report this snippet  

You need to login to post a comment.