I created a simple bisection method program. But im trying to store my values in an array as below. However everytime i run it, it only updates the first element of the array, and doesnt update each other element in the array after each loop:
function [m] = BisectionMethodTEST(func,x0,x1)% x0 is the left endpoint
% x1 is the right endpoint
err = input('Enter the error: ');TOL = input('Enter total iterations: ');format compacty = zeros(1,TOL);m = zeros(1,TOL);p = zeros(1,TOL);flog = 0; %Break out of nested loops
for i = 1:(TOL - 1) while abs(x1 - x0) > err m(i+1) = m(i) + (x0 + ((x1 - x0)/2)) y(i+1) = y(i) + func(m(i+1)) if y(i+1) < 0 x0 = m(i+1) else x1 = m(i+1) end if p(i+1) > TOL flog = 1; break end end p(i+1) = p(i) + 1 if flog == 1 %this statement breaks out of nested loops
break endendend
Best Answer