% EXAMPLE: Implied volatility using Black-Scholes:
T=1; S0=100; K=S0; r=0.03;
f = @(sig) BS(T,S0,K,r,sig)  % Call option price
a=0.05; b=0.95;  % initial range of volatilities
y = 10.00;       % make sure f(a)<y and f(b)>y !
bisection(f,y,a,b,0.001)
% EXAMPLE:  Implied volatility using CRR:
T=1; S0=100; K=S0; r=0.03;  N=100;
g = @(sig) CRR(T,S0,K,r,sig,N)(1,1) % returns C(0)
a=0.05; b=0.95;  % initial range of volatilities
y = 10.00;       % make sure g(a)<y and g(b)>y !
bisection(g,y,a,b,0.001)
% EXAMPLE:  Implied volatility using CRRa:
T=1; S0=100; K=S0; r=0.03;  N=100;
h = @(sig) CRRa(T,S0,K,r,sig,N)(1,1) % returns C(0)
a=0.05; b=0.95;  % initial range of volatilities
y = 10.00;       % make sure h(a)<y and h(b)>y !
bisection(h,y,a,b,0.001)
