% MATLAB file:   mixed_layer_wind1.m    (rev: 5/20/2002)
% modified by S. Krueger (10-5-06)

% Demo script to iteratively solve eqs. (5.20) and (5.21)
% for u and v using geostrophic wind as first guess.
% Geostrophic wind, ug, varies from 1 to 20 m/s
% Note that solution does not converge for ug greater than 19 m/s
clear all
close all
ug = zeros(1,20);
Vb= ug;                              % Magnitude of mixed layer wind

    ug = [1:20];                      % Geostrophic wind in increments of 1 m/s
    vg = ug * 0;
    kappa = 0.05;                   % coefficient for mixed layer (s/m)

    %initialize u, v to geostrophic values
    u = ug;
    v = vg;
    Vb = abs(+u+i*v);           % initialize wind magnitude to geostrophic
    
    % Iterate to find boundary layer solution
    
    for n = 1:12
        v = vg + kappa*Vb.*u;    
        u = ug - kappa*Vb.*v;       
        Vb = abs(+u+i*v) ;        % new estimate for Vb
    end                             

[ug',u',v']
plot(ug,u, '--',ug,v,':',ug, Vb, 'k',ug,ug,'*')
xlabel('geostrophic wind (m/s)');
ylabel('speed (m/s)');
title('ug (stars); V (solid); u (dashed); v (dotted)');

