import java.util.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import javax.swing.*;

public class HT1_duvar
{

public static double fx(double lambda,double Bi)
{return lambda*Math.tan(lambda)-Bi;}

public static double dfx(double x,double h,double Bi)
{ //Türev hesabı
  return (-fx((x+2.0*h),Bi)+8.0*fx((x+h),Bi)-8.0*fx((x-h),Bi)+fx((x-2.0*h),Bi))/(12.0*h);
}

public static double Cn(double ln,double Bi)
{
 return 4.0*Math.sin(ln)/(2.0*ln+Math.sin(2.0*ln));
}

public static double lambda(int n,double Bi)
{
	 double x1=(n-1)*Math.PI;
     double x2=	x1+Math.PI/2-0.00000001;	
    double ITMAX=100;
    double EPS=3.0e-8;
	int iter;
	double a=x1,b=x2,c,d,e,min1,min2;
	double tol=1.0e-5;
	c=0;
	d=0;
	e=0;
	double fa=fx(a,Bi),fb=fx(b,Bi),fc,p,q,r,s,tol1,xm;
	if (fb*fa > 0.0) JOptionPane.showMessageDialog(null,"Kök sınırları doğru olarak seçilmemiş \n sonuç hatalı olabilir"
	,"KÖK SINIRLARI SEÇİM UYARISI",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=fx(b,Bi);
	}
	JOptionPane.showMessageDialog(null,"n="+n+"Uyarı maximum iterasyon sayısı aşıldı \n"+
   " çözüm geçerli olmıyabilir","MAKSİMUM ITERASYON SAYISI UYARISI",JOptionPane.WARNING_MESSAGE);
return b;
}

public static double teta(double Fo,double Bi,double x)
{double tt=0;double ln=0;double cn;
 for(int n=1;n<20;n++)
 {ln=lambda(n,Bi);cn=Cn(ln,Bi);tt+=cn*Math.exp(-ln*ln*Fo)*Math.cos(ln*x);}
 return tt;	
}

     public static void main (String args[])  
     {  
	 fb f=new fb(); 
     double Bi,Fo;
     Fo=Double.parseDouble(JOptionPane.showInputDialog(" Forier sayısı Fo : "));
     Bi=Double.parseDouble(JOptionPane.showInputDialog(" Biot sayısı   Bi : "));
     //x=Double.parseDouble(JOptionPane.showInputDialog("         x* = x/L : "));
     double x[]=new double[51];
     double teta[]=new double[51];
     for(int i=0;i<=50;i++)
     {x[i]=(double)i/50.0;
      teta[i]=teta(Fo,Bi,x[i]);
     }
     Plot p=new Plot(x,teta);
     p.plot();
     } 
}