Bisection method


/ Published in: C
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.