import javax.swing.*;
public class su1
{
double tc;//derece c
double pc;//bar
public su1()
{tc=374.136;//C
 pc=220.88;//bar
}
public double ps(double t)
{double F[]={-741.9242,-29.72100,-11.55286,-0.8685635,0.1094098,0.439993,0.2520658,0.05218684};
 double T=t+273.16;
 double to=1000.0/T;
 double xx=0.65-0.01*t;
 double carpi=1.0;
 double toplam=0;
 for(int i=0;i<F.length;i++)
 {toplam+=F[i]*carpi;
  carpi*=xx;
 }
 double pp=pc*Math.exp(to*1e-5*(tc-t)*toplam);
 return pp;
}

public double tts(double t,double pi)
{return ps(t)-pi;}
public double ts(double ps)
{return brent(1.0,100.0,ps);}
public  double brent(double t1,double t2,double pi)
{
    // roots of the nonlinear equation: Brent method
    // referance : Numerical Recipes in C, second edition, William H. Press, 
    // Saul A. Teukolsky, William T. Vetterling, Brian P. Flannery
    // cambridge university press	
	double ITMAX=200;
               double EPS=2.22044604925031e-12;
	int iter;
	double a=t1,b=t2,c,d,e,min1,min2;
	double tol=1.0e-12;
	c=0;
	d=0;
	e=0;
	double fa=tts(a,pi),fb=tts(b,pi),fc,p,q,r,s,tol1,xm;
	if (fb*fa > 0.0) JOptionPane.showMessageDialog(null,"Root limit selection is uncorrect \n result may be wrong"
	,"ROOT LIMITS WARNING",JOptionPane.WARNING_MESSAGE);
	fc=fb;
	for (iter=1;iter<=ITMAX;iter++) 
	{
		if (fb*fc > 0.0) {
			c=a;
			fc=fa;
			e=d=b-a;
		}
		if (Math.abs(fc) < Math.abs(fb)) {
			a=b;
			b=c;
			c=a;
			fa=fb;
			fb=fc;
			fc=fa;
		}
		tol1=2.0*EPS*Math.abs(b)+0.5*tol;
		xm=0.5*(c-b);
		if (Math.abs(xm) <= tol1 || fb == 0.0) return b;
		if (Math.abs(e) >= tol1 && Math.abs(fa) > Math.abs(fb)) {
			s=fb/fa;
			if (a == c) {
				p=2.0*xm*s;
				q=1.0-s;
			} else {
				q=fa/fc;
				r=fb/fc;
				p=s*(2.0*xm*q*(q-r)-(b-a)*(r-1.0));
				q=(q-1.0)*(r-1.0)*(s-1.0);
			}
			if (p > 0.0)  q = -q;
			p=Math.abs(p);
			min1=3.0*xm*q-Math.abs(tol1*q);
			min2=Math.abs(e*q);
			if (2.0*p < (min1 < min2 ? min1 : min2)) {
				e=d;
				d=p/q;
			} else {
				d=xm;
				e=d;
			}
		} else {
			d=xm;
			e=d;
		}
		a=b;
		fa=fb;
		if (Math.abs(d) > tol1)
			b += d;
		else
			b += (xm > 0.0 ? Math.abs(tol1) : -Math.abs(tol1));
		fb=tts(b,pi);
	}
return b;
}

public static void main(String arg[])
{su1 s=new su1();
 double ps=s.ps(90.0);
 double ts=s.ts(ps);
 System.out.println("ps="+ps+"bar ts="+ts+"derece C");
 
}
}