二分法解方程MATLAB

clear
a=input('a=');
b=input('b=');
e=input('c=');
c=(a+b)/2
n=log2((b-a)/e)-1
if f(a)*f(b)>0
    Solution='May be No Solution'
else
    if f(c)==0
        Solution=c
    else
        for i=1:1:n
            c=(a+b)/2
            if f(c)<0
                a=c
            else
                b=c
            end
        end
        Solution=c
    end
end

       
posted @ 2006-02-09 16:09  陕北蜂农  阅读(512)  评论(0编辑  收藏  举报