Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- f(x) = x^3-x-2
- a = 1
- b = 2
- Ans:
- 1.5
- 1.75
- 1.625
- 1.5625
- */
- function[] = bisection(f);
- a=input('Value of a: ')
- b=input('Value of b: ')
- if(f(a)*f(b)<0)
- for i=1:4
- x=(a+b)/2;
- if(f(x)*f(b)<0)
- a=x;
- else
- b=x;
- end
- disp(x);
- end
- end
- endfunction;
- deff('y=f(x)',['y=x^3-x-2'])
- bisection(f)
Add Comment
Please, Sign In to add comment