diff options
author | priyanka | 2015-06-24 15:03:17 +0530 |
---|---|---|
committer | priyanka | 2015-06-24 15:03:17 +0530 |
commit | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch) | |
tree | ab291cffc65280e58ac82470ba63fbcca7805165 /60/DEPENDENCIES/bisect.sce | |
download | Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2 Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip |
initial commit / add all books
Diffstat (limited to '60/DEPENDENCIES/bisect.sce')
-rwxr-xr-x | 60/DEPENDENCIES/bisect.sce | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/60/DEPENDENCIES/bisect.sce b/60/DEPENDENCIES/bisect.sce new file mode 100755 index 000000000..23216d2bf --- /dev/null +++ b/60/DEPENDENCIES/bisect.sce @@ -0,0 +1,28 @@ +function x=bisection(a,b,f) + N=100; //define max. number of iterations + PE=10^-4 //define tolerance + if (f(a)*f(b) > 0) then + error('no root possible f(a)*f(b) > 0') // checking if the decided range is containing a root + abort; + end; + if(abs(f(a)) <PE) then + error('solution at a') // seeing if there is an approximate root at a, + abort; + end; + if(abs(f(b)) < PE) then //seeing if there is an approximate root at b, + error('solution at b') + abort; + end; + x=(a+b)/2 + for n=1:1:N //initialising 'for' loop, + p=f(a)*f(x) + if p<0 then b=x ,x=(a+x)/2; //checking for the required conditions( f(x)*f(a)<0), + else + a=x + x=(x+b)/2; + end + if abs(f(x))<=PE then break // instruction to come out of the loop after the required condition is achived, + end + end + disp(n," no. of iterations =") // display the no. of iterations took to achive required condition, +endfunction
\ No newline at end of file |