function [v] = BS_IV(PC, S, X, P, T, r)

x1 = 0.000001;
x2 = 0;
y1 = BS_TheoV(PC, S, X, T, x1, r) - P;
y2 = 0;

while y1 * y2>=0,
    x2 = x2 + 1;
    y2 = BS_TheoV(PC, S, X, T, x2, r) - P;
end

while x2 - x1>0.000001,
    k = (x1+x2) / 2;
    y = BS_TheoV(PC, S, X, T, k, r) - P;
    if y * y1>0
        x1 = k;
        y1 = y;
    else
        x2 = k;
    end
end

v=(x1+x2)/2;