0% found this document useful (0 votes)
9 views4 pages

Math Proj

Uploaded by

Hajar Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Math Proj

Uploaded by

Hajar Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

package mathproj;

import java.lang.Math;

import java.util.Scanner;

public class proj {

static double x ;

public static void main(String [] args) {

System.out.println("enter the lower value a :");


Scanner a1 = new Scanner(System.in);
double a = a1.nextDouble();

System.out.println("enter the upper value b :");


Scanner b1 = new Scanner(System.in);
double b = b1.nextDouble();

System.out.println("enter the value of N :");


Scanner n1 = new Scanner(System.in);
double n = n1.nextDouble();

System.out.println("Please choose the type of function");


System.out.print("1"); System.out.println(": trigonometric function");
System.out.print("2"); System.out.println(": exponential function");
System.out.print("3"); System.out.println(": logarithmic function");
System.out.print("4"); System.out.println(": power function");
System.out.print("5"); System.out.println(": square root function");

Scanner sc = new Scanner(System.in);


double func = sc.nextDouble();

if(func == 1) {
System.out.println("Please choose a function");
System.out.print("1"); System.out.println(": cos");
System.out.print("2"); System.out.println(": sin");
Scanner sc1 = new Scanner(System.in);
double func1 = sc1.nextDouble();

if(func1 == 1) {

System.out.println("type whats inside the cos(");


Scanner val = new Scanner(System.in);
double x = val.nextDouble();

System.out.println(Math.cos(x));

}
else if(func1 == 2) {

System.out.println("type whats inside the sin(");


Scanner vals = new Scanner(System.in);
double x = vals.nextDouble();

System.out.println(Math.sin(x));

}
else if(func == 2) {

double h = b - a;
double answ = (h/2)* (Math.exp(a) + Math.exp(b));
System.out.println("trap rule : "+answ);

double h_n = (b - a) / n;
double f_answ = h_n * (Math.exp(a) + Math.exp(b));
for (int i = 1; i < n; i++) {
double x = (a + (h * i));
f_answ = f_answ + Math.exp(x);
}
System.out.println("comp trap rule : "+ f_answ * h_n);
double S1rule = ((b-a)/n)*(Math.exp(a)+ (4
*(Math.exp(a+b)/2))+(Math.exp(b)));
System.out.print("Simpson’s 1/3 rule rule : "+ S1rule);
}

else if(func == 3) {
System.out.println("type the value inside the log");
Scanner sc3 = new Scanner(System.in);
double value1 = sc3.nextDouble();
double h = b - a;
double answ1 = (h/2)* (Math.log10(a) + Math.log10(b));
System.out.println("trap rule : "+answ1);

double h_n = (b - a) / n;
double f_answ = h_n * (Math.log10(a) + Math.log10(b));
for (int i = 1; i < n; i++) {
double x = a + h * i;
f_answ = f_answ + Math.log10(x);
}
System.out.print("comp trap rule : "+ f_answ * h_n);

}
else if(func == 4) {
System.out.println("enter the power of x");
Scanner sc4 = new Scanner(System.in);
double value2 = sc4.nextDouble();
double h = b - a;
double answ2 = (h/2)* (Math.pow(a,value2) + Math.pow(b,value2));
System.out.println("trap rule : "+answ2);

double h_n = (b - a) / n;
double f_answ = h_n * (Math.pow(a,value2) + Math.pow(b,value2));
for (int i = 1; i < n; i++) {
double x = a + h * i;
f_answ = f_answ + Math.pow(x,value2);
}
System.out.print("comp trap rule : "+ f_answ * h_n);

double S1rule = ((b-a)/6)*(Math.pow(a,value2)+ (4


*(Math.pow(a,value2+b)/2))+(Math.pow(b,value2)));
System.out.print("Simpson’s 1/3 rule rule : "+ S1rule);

}
else if(func == 5) {
System.out.println("type the function under the root");
Scanner sc5 = new Scanner(System.in);
double value3 = sc5.nextDouble();
double h = b - a;
double answ3 = (float) ((h/2)* (Math.sqrt(value3*b) +
Math.sqrt(value3*a)));
System.out.println("trap rule : "+answ3);

double h_n = (b - a) / n;
double f_answ = h_n * (Math.sqrt(b) + Math.sqrt(a));
for (int i = 1; i < n; i++) {
double y = a + h * i;
f_answ = f_answ + Math.sqrt(y);
}
System.out.println("comp trap rule : "+ f_answ * h_n);

double S1rule = ((b-a)/6)*(Math.sqrt(a)+ (4


*(Math.sqrt(a+b)/2))+(Math.sqrt(b)));
System.out.print("Simpson’s 1/3 rule rule : "+ S1rule);

You might also like