martes, 29 de agosto de 2017

Simulaciones Probabilisticas Correlacionales

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package simulacion;

import java.awt.Canvas;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import javax.swing.ImageIcon;

/**
 *
 * @author m
 */
public class Imagen extends Canvas {
    List x=new ArrayList<Integer>();
    List y=new ArrayList<Integer>();
 
 
    Image i,ii;
 
    public void generarX(){
        int respuesta=0;
        for(int a=0;a<=100;a++){
             // int c=TheadLocalRandom.current().nexInt(10,100);
             respuesta = ThreadLocalRandom.current().nextInt(10,150);
            x.add(respuesta);
        }
    }
    public void generarY(){
        int respuesta=0;
        for(int a=0;a<=100;a++){
            respuesta = ThreadLocalRandom.current().nextInt(10,150);
            y.add(respuesta);
        }
    }
    public Imagen(){
        generarX();
        generarY();
        ii=new ImageIcon("uno.jpg").getImage();
        i=new ImageIcon("dos.jpg").getImage();
     
    }
 
    public void paint(Graphics g){
        int c=0,n=0;
        float p=0,p1=0;
        String q,qq;
        g.drawImage(i, 10, 10, null);
        g.drawImage(ii, 250, 10, null);
        for(int a=0;a<100;a++){
            q=String.valueOf(x.get(a));
            qq=String.valueOf(y.get(a));
            int num=Integer.parseInt(q);
            int num2=Integer.parseInt(qq);
         
            if(num>0 &&num<=50 && num2>0 &&num2<=50){
               c++;
         
            }else{
                n++;
            }
         
       // g.fillOval(Integer.parseInt(q),Integer.parseInt(qq), 16, 16);  
        g.drawOval(num,num2, 6, 6);
        g.drawRect(0, 0, 50, 50);
    }
        p=((c)%((c)+(n)));
          p1=((n)%((c)+(n)));
  System.out.println("Calleron ---> "+c+" y se salieron ---->"
          + " "+n+"\n\n y la probabilidad de positivos es -->"
          + " "+p+"\n\n la probabilidad de los negativos es ---> "+p1);
   
    }
 
 
    public static void main(String[] args) {
        Frame f= new Frame();
        f.add(new Imagen());
        f.setSize(600, 300);
        f.setVisible(true);
     
    }
 
}

jueves, 24 de agosto de 2017

Canvas Imagenes

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package simulacion;

import java.awt.Canvas;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import javax.swing.ImageIcon;

/**
 *
 * @author m
 */
public class Imagen extends Canvas {
    List x=new ArrayList<Integer>();
    List y=new ArrayList<Integer>();
   
   
    Image i,ii;
   
    public void generarX(){
        int respuesta=0;
        for(int a=0;a<100;a++){
             // int c=TheadLocalRandom.current().nexInt(10,100);
             respuesta = ThreadLocalRandom.current().nextInt(10,150);
            x.add(respuesta);
        }
    }
    public void generarY(){
        int respuesta=0;
        for(int a=0;a<100;a++){
            respuesta = ThreadLocalRandom.current().nextInt(10,150);
            y.add(respuesta);
        }
    }
    public Imagen(){
        generarX();
        generarY();
        ii=new ImageIcon("uno.jpg").getImage();
        i=new ImageIcon("dos.jpg").getImage();
       
    }
   
    public void paint(Graphics g){
        g.drawImage(i, 10, 10, null);
        g.drawImage(ii, 250, 10, null);
        for(int a=0;a<=100;a++){
            String q=String.valueOf(x.get(a));
            String qq=String.valueOf(y.get(a));
           
        g.fillOval(Integer.parseInt(q),Integer.parseInt(qq), 8, 8);
       
    }
 
     
    }
   
   
    public static void main(String[] args) {
        Frame f= new Frame();
        f.add(new Imagen());
        f.setSize(600, 300);
        f.setVisible(true);
       
    }
   
}



miércoles, 23 de agosto de 2017

Canvas

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package simulacion;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;

/**
 *
 * @author m
 */
public class Imagen extends Canvas {
   
    Image i;
   
    public Imagen(){
        i=new ImageIcon("dd.jpg").getImage();
    }
    public void paint(Graphics g){
        g.drawImage(i, 80, 80, null);
 
     
    }
   
    public static void main(String[] args) {
        Frame f= new Frame();
        f.add(new Imagen());
        f.setSize(800, 800);
        f.setVisible(true);
       
    }
   
}

martes, 22 de agosto de 2017

simulacion

                                                                 Método de Monte Carlo

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package simulacion;

import java.text.DecimalFormat;

/**
 *
 * @author m
 */
public class MetodoMontecarlo {
   
    public static void main(String[] args) {
        MetodoMontecarlo m=new MetodoMontecarlo();
       
        for(int x=0;x<=100;x++){
         
            System.out.println("Numero seudoaleatorios "+x+" -----> "+m.Metodo());
        }
       
    }
   
    public int Metodo(){
        int respuesta=0;
        double x=Math.random();
         DecimalFormat d=new DecimalFormat("#.000");
         String n=d.format(x);
         float c=Float.parseFloat(n);
         if(c<=0 || c<=0.125){
             respuesta=1;
         }else if(c<=0.125 || c<=0.250){
             respuesta=2;
         }else if(c<=0.250 || c<=0.375){
             respuesta=3;
         }else if(c<=0.375 || c<=0.5){
             respuesta=4;
         }else if(c<=0.5 || c<=0.625){
             respuesta=5;
         }else if(c<=0.625 || c<=0.750){
             respuesta=6;
         }else if(c<=0.750 || c<=0.875){
             respuesta=7;
         }else if(c<=0.875 || c<=1){
             respuesta=8;
         }
       
        return respuesta;
    }
   
}



                                                           Método Mixto


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package simulacion;

/**
 *
 * @author m
 */
public class MetodoMixto {
   
    public static void main(String[] args) {
        int xx=8;
        MetodoMixto m=new MetodoMixto();
        for(int y=0;y<=100;y++){
            xx=m.Metodo(xx);
        System.out.println("Numero seudoaleatorios "+y+" -----> "+m.Metodo(xx));
        }
    }
   
   
    public int Metodo(int y){
       
         int a=3,x,xx;
         int c=6;
         int m=7;
         int xn=y;
     
         x=((a*(xn))+c);
          xx=x%m;
     
         return xx;
    }
   
}