Calculation of the Z value of the normal distribution

1

Good morning, I'm having a problem in calculating the Z value in the normal distribution. Also the calculation of the constants t and sigma t are giving me 0, which is impossible. I'll put the code and the output.

The calculation can be seen on the following website: link

Of course in Java you can calculate, I was doing some research and found a method but it is not working very well.

The code I'm using is:

 import java.io.*;
 import static java.lang.Math.sqrt;
 import org.apache.commons.math.distribution.NormalDistribution;
 import org.apache.commons.math.distribution.NormalDistributionImpl;

 public static void main(String[] args) throws MathException
 {        
     //constantes
     double PARAGEM=0.1; //crit. paragem função objetivo
     int ITERACOES=90; //nº max de iterações
     int ESPERA;  //tempo máximo de espera

     //variáveis
     double  A=80000; //custo de encomenda (euros)
     double C1=40000; //custo de compra (euros/ton)
     double C2=16000; //custo de stocagem (euros/ton)       
     double C3=150000; //custo de roptura (euros/ton)
     double r=44.4; //procura média (ton/ano)       
     double sigma2=0.001; //variância da procura (ton/ano)        
     double t=(60/365); //tempo medio de reposição (anos)  **//NOTA: Esta conta está a dar-me 0, não percebo porquê**
     double sigmat=(20/365); //desvio padrão do tempo de reposição (anos) **//NOTA: Esta conta está a dar-me 0, não percebo porquê**
     String distribuicao;

     //cálculo do lote otimo (diferente para a 1ª iteração)
     double Q1;
     Q1=(sqrt((2*A*r)/C2));

     //calculo de alfa
     double alfa1;
     alfa1=(C2*Q1)/C3/r;        

     //calculo de z1
     //NormalDistributionImpl recebe média, desvio padrão
     NormalDistributionImpl z1=new NormalDistributionImpl(r,sigma2);
     z1.inverseCumulativeProbability(1-alfa1);



    System.out.println("O valor de Q1 é "+ Q1);   
    System.out.println("O valor de alfa1 é "+ alfa1);  

    System.out.println("O valor de Z1 é "+ z1);

Output

The value of Q1 is 21.071307505705477 The value of alpha1 is 0.05062175977346662 The value of Z1 is org.apache.commons.math.distribution.NormalDistributionImpl@36ed5ba6 The value of t is 0.0 The value of sigmat is 0.0 BUILD SUCCESSFUL (total time: 0 seconds)

Can someone help me?

Thank you

    
asked by anonymous 11.05.2015 / 14:59

2 answers

0

Thanks for the help, I already managed to resolve the issue, the correct code would then be:

import static java.lang.Math.sqrt; import org.apache.commons.math.distribution.NormalDistribution; import org.apache.commons.math.distribution.NormalDistributionImpl;

public class OptimizationStocks {

 public static void main(String[] args) throws MathException
 {        

double A = 80000.0; // order cost (euros)          double C1 = 40000.0; // purchase cost (EUR / tonne)          double C2 = 16000.0; // stowage cost (EUR / ton)
         double C3 = 150000.0; // cost of collection (EUR / tonne)          double r = 44.4; // average demand (ton / year)
         double sigma2 = 0.0; // variance of demand (ton / year)
         double t = (60.0 / 365.0); // average replacement time (years)          double sigmat = (20.0 / 365.0); // standard deviation of replacement time (years)          String distribution;

// calculation of the optimal lot (different for the 1st iteration)          double Q1;          Q1 = (sqrt ((2 * A * r) / C2));

     //calculo de alfa
     double alfa1;
     alfa1=(C2*Q1)/C3/r;        

     //calculo de z1
     NormalDistributionImpl z1=new NormalDistributionImpl(0,1);
     double z1resultado= z1.inverseCumulativeProbability(1-alfa1);         

     //calculo de m1   
     double m1;
     double mulinha= (t*r);
     double sigmalinha;
     //Ver o que se passa com sigmalinha
     sigmalinha=sqrt(sigmat*r+sigmat*r+sigmat*sigma2);
     m1= mulinha+sigmalinha*z1resultado;

    System.out.println("O valor de Q1 é "+ Q1);   
    System.out.println("O valor de alfa1 é " + alfa1);  
    System.out.println("O valor de Z1 é "+ z1resultado);
    System.out.println("O valor de mulinha é "+ mulinha);
    System.out.println("O valor de sigmalinha é "+ sigmalinha);
    System.out.println("O valor de M1 é "+ m1);


 }

}

Output

The value of Q1 is 21.071307505705477 The value of alpha1 is 0.05062175977346662 The value of Z1 is 1.6388547211994033 The value of the moth is 7.298630136986301 The value of sigmalinha is 2.2058452857481945 The value of M1 is 10.913690097770177 BUILD SUCCESSFUL (total time: 0 seconds)

    
13.05.2015 / 15:26
1

The lines ...

double t=(60/365);
double sigmat=(20/365);

... are giving zero because you are dividing integers. Try to do this:

double t=(60.0/365.0);
double sigmat=(20.0/365.0);

The line ...

z1.inverseCumulativeProbability(1-alfa1);

... you need to save the result to a variable:

NormalDistributionImpl distribuicao = new NormalDistributionImpl(r, sigma2);
double z1 = distribuicao.inverseCumulativeProbability(1-alfa1);
System.out.println("O valor de Z1 é "+ z1);
    
11.05.2015 / 15:43