function result = prob_quadratic_RS_test(varargin)
% PROB_QUADRATIC_RS_TEST  RS problem with resp. one, 10 and 25 quadratic terms
%
% Test and comparison routine for a Resistance-Solicitation problem with
% respectively one, 10 and 25 quadratic terms with various reliability methods.
% Test cases obtained from Waarts (2000)
%
%
%   See also

%% Copyright notice
%   --------------------------------------------------------------------
%   Copyright (C) 2011 Deltares
%       Kees den Heijer
%
%       Kees.denHeijer@Deltares.nl
%
%       Deltares
%       P.O. Box 177
%       2600 MH Delft
%       The Netherlands
%
%   This library is free software: you can redistribute it and/or
%   modify it under the terms of the GNU Lesser General Public
%   License as published by the Free Software Foundation, either
%   version 2.1 of the License, or (at your option) any later version.
%
%   This library is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%   Lesser General Public License for more details.
%
%   You should have received a copy of the GNU Lesser General Public
%   License along with this library. If not, see <http://www.gnu.org/licenses/>.
%   --------------------------------------------------------------------

% This tools is part of <a href="http://OpenEarth.Deltares.nl">OpenEarthTools</a>.
% OpenEarthTools is an online collaboration to share and manage data and
% programming tools in an open source, version controlled environment.
% Sign up to recieve regular updates of this function, and to contribute
% your own tools.

%% Version <http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html>
% Created: 13 Jul 2011
% Created with Matlab version: 7.12.0.635 (R2011a)

% $Id$
% $Date$
% $Author$
% $Revision$
% $HeadURL$
% $Keywords: $

MTestCategory.WorkInProgress;

%% set number of samples

if ~isempty(varargin)
    N = varargin{1};
else
    N = 1e4;
end

%% define stochastic variables
% this initial stochastic variable is meant for the case with one quadratic
% term
stochast = struct(...
    'Name', {
    'R'... % example stochastic variable "R" (Resistance or Strength)
    'S1'... % example stochastic variable "S" (Sollicitation or Load)
    },...
    'Distr', {
    @norm_inv... % distribution function (of R)
    @norm_inv... % distribution function (of S)
    },...
    'Params', {
    {11 1}... % mu and sigma (of R)
    {1.5 .5}... % mu and sigma (of S)
    },...
    'propertyName', {
    true... % add propertyname (of R) in z-function call
    true... % add propertyname (of S) in z-function call
    } ...
    );

result(1) = struct('Exact',{struct('Beta', 3.46,'P_f', norm_cdf(3.46,0,1))});
result(2) = struct('Exact',{struct('Beta', 2.98,'P_f', norm_cdf(2.98,0,1))});
result(3) = struct('Exact',{struct('Beta', 2.63,'P_f', norm_cdf(2.63,0,1))});

i = 1;
for nquadratic = [1 10 25]
    if nquadratic > 1
        % in case of more than one quadratic terms, the stochastic
        % variables are adapted and new ones are added
        stochast(1).Params = {.5 .1};
        stochast(2).Params = {.2 .1};
        for nq = 2:nquadratic
            stochast(nq+1) = stochast(2);
            stochast(nq+1).Name = sprintf('S%i', nq);
        end
    end

    %% run FORM
    result(i).FORM = FORM(...
        'stochast', stochast,...
        'x2zFunction', @prob_quadratic_RS_x2z_test);

    %% run Monte Carlo
    result(i).CMC = MC(...
        'stochast', stochast,...
        'x2zFunction', @prob_quadratic_RS_x2z_test,...
        'NrSamples', N);

    %% run Directional Sampling
    result(i).ADIS = DS(...
        'stochast', stochast,...
        'x2zFunction', @prob_quadratic_RS_x2z_test);

    %% print result
    prob_print_test(result(i));

    i = i + 1;
end