% prob 6.11
function out=prob6_11()

g0 = 0.27e-6;
lelec = 7e-6;
w = 10e-6;
l = 71e-6;
t = 1e-6;

e = 8.85e-12;
rho = 2300;
E = 150e9;

A = lelec * w;

k = 16*(E*w*t^3/l^3);
m = t*l*w*rho;

VPI = sqrt(8*k*g0^3/(27*e*A));

V = linspace(0.05*VPI,0.99*VPI,100);

for in=1:length(V)
    V0 = V(in);
    G = fzero(@(G) gap(G,V0,k,e,A,g0),g0);
    C0 = e*A/G;
    phi = C0*V0/G;
    kp(in) = k*(1-C0^2*V0^2/(e*A*k*G));
    C1 = phi^2/kp(in);
    L = m/phi^2;
    w_r(in) = 1/(2*pi)*sqrt(1/(L*C1));
    if in==1
        Z1 = tf([1/C0 0 1/(L*C0*C1)],[1 0 1/L*(1/C0+1/C1) 0]);
    end
    if in==100
        Z2 = tf([1/C0 0 1/(L*C0*C1)],[1 0 1/L*(1/C0+1/C1) 0]);
    end
end

    
w = logspace(6,7,5000);
bode(Z1,'r',Z2,'b',w)
figure
semilogy(V,w_r)


    
function y = gap(G,V0,k,e,A,g0)
y = G - g0 + e*A*V0^2/(2*k*G^2);