Home Nach oben Verteilungen Quelle Laderampe Friseur Salon Job Shop
| |
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Applet1 extends Applet implements Runnable
{
int versuche;
int vert;
int breite;
int max;
int a;
int b;
int e;
int r;
int outOfBound;
int temp;
int yVersatz;
int xVersatz;
Thread verteilung;
public int gleichvert(double a, double b)
{
double temp=0;
temp=(b-a)*Math.random()+a;
return Math.round((float)temp);
}
//Exponentialverteilte WDF: Achtung Intervalle nur bis 3faches des
Erwartungswertes
public int expvert(double a)
{
double temp=0;
temp=-a*Math.log(1-Math.random());
return Math.round((float)temp);
}
//Erlangverteilte WDF: Achtung Intervalle nur bis 3faches des Erwartungswertes
public int erlvert(double a, double b)
{
int i=0;
double temp=0;
while (i<b)
{
temp+=-a*Math.log(1-Math.random());
i++;
}
return Math.round((float)(temp/b));
}
//Rampenverteilte WDF
public int rampenvert(double a, double b)
{
double temp=0;
temp=(b-a)*Math.sqrt((Math.random()/2))+a;
return Math.round((float)temp);
}
//Dreiechverteilte WDF
public int dreieckvert(double a, double b)
{
double temp=Math.random();
double temp2=0;
if (temp<0.5)
{
temp2=(a+(b-a)*Math.sqrt(temp/2) );
}
else
{
temp2=(b-(b-a)*Math.sqrt((1-temp)/2));
}
return Math.round((float)temp2);
}
public void start()
{
if (verteilung==null)
{
repaint();
verteilung=new Thread(this);
verteilung.start();
}
}
public void stop()
{
if (verteilung!=null)
{
verteilung.stop();
verteilung=null;
}
}
public void init()
{
breite =getSize().width-10;
versuche=100*getSize().width;
max=0;
a=20;
b=breite-20;
e=breite/4;
r=5;
outOfBound=0;
yVersatz=getSize().height;
xVersatz=10;
List l =new List(2,false);
l.addItem("Gleich");
l.addItem("Expotential");
l.addItem("Erlang");
l.addItem("Rampre");
l.addItem("Dreieck");
l.addActionListener (new
ActionListener()
{
public void actionPerformed(ActionEvent
e)
{
if (e.getActionCommand().equals("Gleich"))
{
vert = 1;
}
else if (e.getActionCommand().equals("Expotential"))
{
vert = 2;
}
else if (e.getActionCommand().equals("Erlang"))
{
vert = 3;
}
else if (e.getActionCommand().equals("Rampre"))
{
vert = 4;
}
else if (e.getActionCommand().equals("Dreieck"))
{
vert = 5;
}
stop();
start();
}
});
add(l);
}
public void run()
{
try
{
for (;;)
{
int histo[] = new int[breite];
Graphics g = getGraphics();
for (int i=0;i<versuche;i++)
{
temp=0;
switch(vert)
{
case 1:
{
temp=gleichvert(a,b);
break;
}
case 2:
{
temp=expvert(e);
break;
}
case 3:
{
temp=erlvert(e,r);
break;
}
case 4:
{
temp=rampenvert(a,b);
break;
}
case 5:
{
temp=dreieckvert(a,b);
break;
}
}
if (temp>=breite | temp<0) outOfBound++;
else histo[temp]++;
}
max=0;
for (int i=0;i<breite;i++)
{
if (max<histo[i])
{
max=histo[i];
}
}
g.setColor(getBackground());
g.fillRect(0,0,getSize().width,getSize().height);
g.setColor(Color.black);
int i=0;
for (int x=xVersatz;x<breite+xVersatz;x++)
{
int y =yVersatz-histo[i++]*(yVersatz-50)/max;
g.drawLine(x,yVersatz,x,y);
}
verteilung.sleep(50);
}
}
catch (InterruptedException ex)
{
System.out.println(ex);
}
}
}
|