Calculation of the Z value of the normal distribution

Asked

Viewed 895 times

1

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

The calculation can be seen on the following website: http://www.portalaction.com.br/probabilidades/62-distribuicao-normal

Surely in java you can calculate, I’ve been doing some research and I found a method but it’s 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 alpha 1 is 0.05062175977346662 The value of Z1 is org.apache.Commons.math.Distribution.Normaldistributionimpl@36ed5ba6 The value of t is 0.0 The sigmat value is 0.0 BUILD SUCCESSFUL (total time: 0)

Can someone help me?

Thank you

2 answers

1

The lines...

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

...are giving zero because you are dividing whole. Try to do so:

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

Already the line...

z1.inverseCumulativeProbability(1-alfa1);

...need to store the result in a variable:

NormalDistributionImpl distribuicao = new NormalDistributionImpl(r, sigma2);
double z1 = distribuicao.inverseCumulativeProbability(1-alfa1);
System.out.println("O valor de Z1 é "+ z1);
  • Thank you for the previous reply which was quite useful. Z is supposed to be giving 1.638854721 Because in Excel it is much easier, just do: INV.NORMP(1-alpha 1) (in excel in Portuguese) or NORMSINV(1-alpha 1) (in excel in English) This function returns the value of the cumulative function of the standard normal. alpha= 0.051 1-alpha=0.949 INV.NORMP(0.949)= 1.6388 This function is not returning this, I’m trying to find the equivalent function in java.

0


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

import Static java.lang.Math.sqrt; import org.apache.Commons.math.Distribution.Normaldistribution; import org.apache.Commons.math.Distribution.Normaldistributionimpl;

public class Optimizacaodestocks {

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

double A=80000.0; //order cost (euros) double C1=40000.0; //purchase cost (EUR/ton) double C2=16000.0; //stoation cost (EUR/ton)
double C3=150000.0; //rope cost (EUR/ton) 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 the 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 alpha 1 is 0.05062175977346662 The value of Z1 is 1.6388547211994033 The fine value is 7.298630136986301 The sigmaline value is 2.2058452857481945 The value of M1 is 10.913690097770177 BUILD SUCCESSFUL (total time: 0)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.