function [err,stat] = WeakCounterEx(N, M)
    A1 = [0,1,1;-1,0,1;-1,-1,0];
    A2 = [0,0.5,-0.5;-0.5,0,0.3;0.5,-0.3,0]
    A = 0.5*A1*A1+0.5*A2*A2;
    function y = Vdr(x)
        y = A*x;
    endfunction
    function y = Vdi(x)
        y = [A1*x,A2*x];
    endfunction
    S0 = [1;0;0];
    T = 1;
    mu = 0;
    mu2 = 0;
    
    for i=1:M
        [Xbar, dB] = EulerTrajectory(S0, Vdr, Vdi, 2, N, T);
        mu = mu + max(norm(Xbar)-1,0);
        mu2 = mu2 + max(norm(Xbar)-1,0)^2;
    end
    err = abs(mu/M - 0);
    sd = sqrt(mu2/M-(mu/M)^2);
    stat = 1.65*sd/sqrt(M);
endfunction