Thread: Matlab
View Single Post
Old 07-25-2003, 03:48 PM   #26 (permalink)
slant eyes
Psycho
 
Location: cali
ok, here is one algorithm. forgive me if it's newb-ish.

Code:
a = 0;
b = 0;
TOL = 0;
N0 = 0;
p = 0;
i = 1;

a = input('Please enter starting endpoint "a" for the Bisection Method');
b = input('Please enter starting endpoint "b" for the Bisection Method');
TOL = input('Please enter desired tolerance for the Bisection Method');
N0 = input('Please enter maximum number of iterations for the Bisection Method');

FA = f(a);

for i = i:N0
    p = a + (b - a) / 2;
    FP = f(p);
    if FP = 0 | (b - a) / 2 < TOL;
        disp(sprintf('%5.6f', p);
    end
    else i = i + 1;
        if FA * FP > 0;
            a = p;
            FA = FP;
        else b = p;
        disp('Method failed after N0 iterations, N0 =', N0);
    end
slant eyes is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73