You are on page 1of 4

/*

* To change this template, choose Tools | Templates


* and open the template in the editor.
*/
package halfinterval1;
import java.util.Scanner;
/**
*
* @author usre
*/
public class HalfInterval1 {
/**
* @param args the command line arguments\
* This program will compute the roots of f(x)=sin 10x + cos 3x
* Half Interval method will be used for iteration(looping method)
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
double Xl,Xu,fXl,fXu,f,a,b,Xm,fXm,k;

System.out.printf("Please enter your initial value: ");


a=input.nextDouble();
System.out.printf("Please enter your final value: ");
b=input.nextDouble();

k=0;
fXl=Math.sin(10*a) + Math.cos(3*a);
fXu=Math.sin(10*b) + Math.cos(3*b);
f=(fXl*fXu);
System.out.printf("\n k\t x1\t x2\t xa\t fxa\t");
if (f<0)
{
Xl=a;
Xu=b;
do
{
Xm=((Xl+Xu)/2.0);
fXm=Math.sin(10*Xm) + Math.cos(3*Xm);

if(fXm<0)
Xl=Xm;
else

Xu=Xm;
System.out.printf("\n%3.0f %18.4f %18.4f %18.4f
%18.4f",k,Xl,Xu,Xm,fXm);
k=k+1;
}
while(Math.abs(fXm)>0.0001);
System.out.printf("\nThe value of x is %16.4f",Xm);
}
else
{
System.out.println("\n\nOne or more roots are within the given limits!!!");
main(args);
}

System.out.println();

}
}

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package newtonraphson;
import java.util.Scanner;
/**
*
* @author usre
*/
public class NewtonRaphson {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
double x,fx, fx2;
int c=1;
System.out.print("Enter the estimated root: ");
x = input.nextDouble();
System.out.println("\ncounter x fx");

do{
fx = Math.sin(2*x)-Math.exp(x-1);
fx2 = 2*Math.cos(2*x)-Math.exp(x-1);
System.out.printf("\n %d %10.4f %11.4f", c,x,fx);
x = x -(fx/fx2);
c++;
}
while((Math.abs(fx))>=0.00001);

System.out.printf("\nThe root of the equation is: %5.4f\n\n", x);


}
}

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dopressure;
import java.util.Scanner;
/**
*
* @author usre
*/
public class DoPressure {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
double S,E,T,psi,mmHg,ftH2O,bar;
System.out.print("Please enter the starting pressure value in psi:");
S=input.nextDouble();
System.out.print("Please enter the ending pressure value in psi:");
E=input.nextDouble();

System.out.print("\n psi\t mmHg\t ftH2O\t bar\n");


psi=S;
T=E+5.0;

do
{

mmHg=psi*(760/14.7);
ftH2O=psi*(33.899/14.7);
bar=psi*(101325/(14.7*100000));

System.out.printf("\n%11.4f\t %11.4f\t %11.4f\t


%11.4f\t",psi,mmHg,ftH2O,bar);
psi=psi+5.0;

}
while(psi!=T);

}
}

You might also like