private static double integratedFirstOrderStockFunction(RealDistribution demand, double x, UnivariateIntegrator integrator, double accuracy){
		StockIntegrand Integrand = new StockIntegrand(demand, x);
		
		
		try{
			double min = demand.inverseCumulativeProbability(accuracy);
			double max = x;
			double aux =  integrator.integrate(4096, Integrand, min, max);
			return aux;
		}
		catch(IllegalArgumentException ex){
			if (ex.getMessage().contains("endpoints do not specify an interval")) return 0;
			else throw new RuntimeException(ex.toString());
		}
		catch(Exception ex){
			System.out.println("Debug: "+ex);
			throw new RuntimeException(ex.toString());
		}
	}