function Cal_main (allInputs_mean, allInputs_Limit, electrodeValues, h, Savings)
    
f1 = figure;
hold on
%% ================== Pattern Search of Simulation ============================
    % Starting Points
    P1   = 10000;
    P2   = 200;

    P3     = 1;                    
    P4      = 0*P3/100;
    P5  = 10;                   
    P6   = 0*P5/100;
    P7     = 100;                   
    P8      = 0*P7/100;
    P9 = [2; 2; 2];
    P10 = [5000; 5000; 5; 5]; % 

    P11    = 3;                    % How far from mean? 3 = 3xSD to the left (minus) 
    P12      = 3;                    % How far from mean? 3 = 3xSD to the right (plus)
    P13     = 0.1;                    % Step size of bins in "% of mean"

    P14     = 1;
    P15 = 'left';

    % Calc of Gaussian Distribution
    allVariables_Start = [P1, P2, ...
                      P11, P12, P13,...
                      P5, P6, ...
                      P3, P4, ...
                      P7, P8];
    bounds_down_Start = [10000, 200, ...
        3, 3, 0.1, ...
        1, 0, ...
        0.5, 0, ... 
        10, 0];    

    bounds_up_Start = [10000, 200, ...  
        3, 3, 0.1, ... 
        100, 0, ...   
        2, 0, ...   
        1000, 0];   
    allVariables_w = allVariables_Start(1:5);
    bounds_down = bounds_down_Start(1:5);
    bounds_up = bounds_up_Start(1:5);
    for aa = 1:3
        for ii = 1:P14
            % Increase number of Params in allVariables with P14-times for
            % P3,P5,P7
            idx = 5+(aa-1)*2*P14+(ii-1)*2+1;
            allVariables_w(idx:idx+1) = allVariables_Start(5+(aa-1)*2+1:5+(aa-1)*2+2);
            bounds_down(idx:idx+1) = bounds_down_Start(5+(aa-1)*2+1:5+(aa-1)*2+2);
            bounds_up(idx:idx+1) = bounds_up_Start(5+(aa-1)*2+1:5+(aa-1)*2+2);    
        end
    end
    allVariables_w(length(allVariables_w)+1) = P14;
    bounds_down(length(bounds_down)+1) = P14;
    bounds_up(length(bounds_up)+1) = P14;
    allVariables_w(length(allVariables_w)+1:length(allVariables_w)+3) = P9;
    bounds_down(length(bounds_down)+1:length(bounds_down)+3) = P9;
    bounds_up(length(bounds_up)+1:length(bounds_up)+3) = P9;
    allVariables_w(length(allVariables_w)+1:length(allVariables_w)+4) = P10;
    bounds_down(length(bounds_down)+1:length(bounds_down)+4) = P10;
    bounds_up(length(bounds_up)+1:length(bounds_up)+4) = P10;
    
    %% ======================= Different Solvers ====================================
    objfcn = @(allVariables_w)Function_fmincon(allVariables_w,f1);
    % MultiStart
    opts = optimoptions(@fmincon,'OutputFcn',@(x,optimValues,state)outfunFmincon(x,optimValues,state),'Algorithm','interior-point');
    ms = MultiStart('Display','iter','OutputFcn',@(optimValues,state)outfunMulti(optimValues,state));
    problem = createOptimProblem('fmincon', ...
        'x0',allVariables_w,'objective',objfcn, ...
        'lb',bounds_down,'ub',bounds_up,'options',opts);
    [x,fval,exitflag,output,solutions] = run(ms,problem,500); 
end


function stop = outfunFmincon(x,optimValues,state)
    if (1 == 0) 
        stop = true;
    else
        stop = false;
    end
end

function stop = outfunMulti(optimValues,state)
    if (1 == 0) 
        stop = true;
    else
        stop = false;
    end
end

