
// SEMIH YILMAZ COK  FAZLI AKISLI TERMODINAMIK ODEV 1
// 
import java.io.*;
import javax.swing.JOptionPane;


class CFO1b{
     public static void main (String args[]) 
     {
     double T,V,R,a1,b1,c1,d1,Tc,Pc,Vc,w,Pd,u,Tr,w1,fw,x,a,b,P,M,Pc1;
     // O2 gazi icin;  
     M=31.999; // kg/kmol
     R=8314.5/M;   // j/kg.K
     //w=0.025;     
     Tc=145.6; //K
     Pc=504000; //bar
     Pc1=49.75;
     Vc=73.4e-3/M;
    T=108.22;
	//     T=Double.parseDouble(JOptionPane.showInputDialog("T yi giriniz "));
	//     T=Double.parseDouble(JOptionPane.showInputDialog("V yi giriniz "));
     
     
     
     //Doymus Buhar Basinci Katsayilari
     a1=-6.28275; b1=1.73619; c1=-1.81349 ; d1=-0.025364;
     
     // Doymus Buhar Basinci Formulu
     
     //x=1-T/Tc;
     
    //Pd=Math.exp((1/(1-x))*(a1*x+b1*Math.pow(x,1.5)+c1*Math.pow(x,3)+d1*Math.pow(x,6)))* Pc;
     
    //w1= -Math.log10(Pd)-1.0;   // Tr=0.7
    w1=0.025;
    Tr=T/Tc; 
    fw=0.37464+1.54226*w1-0.26992*w1-0.26992*Math.pow(w1,2);
    a=(0.45724*Math.pow(R,2)*Math.pow(Tc,2)/Pc)*Math.pow((1+fw*(1-Math.pow(Tr,0.5))),2);
    b=0.07780*R*Tc/Pc;
    // Peng-Robinson Denklemi    
    double fx[][]=new double[100][500];
    double fy[][]=new double[100][500];
    u=2; w=-1;
    for(int j=0;j<10;j++)
    {	    
    T=100+100*j;
	    for(int i=0;i<500;i++)
    {  V=0.01*i;
      P=(R*T/(V-b))-(a/(V*V+u*b*V+w*b*b));fx[j][i]=V/Vc; fy[j][i]=P/Pc;  }    
    }
    Plot pp=new Plot(fx[0],fy[0]);
    for(int j=1;j<100;j++)
    { pp.addData(fx[j],fy[j]);}
    pp.plot();
    //JOptionPane.showMessageDialog(null,"P degeri:  "+P+"\n w degeri:"+ w1);
     
     }
} 