Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package metoda_simpsona;
- import java.util.Scanner;
- /**
- *
- * @author Student
- */
- public class Metoda_Simpsona {
- public static double caleczka (double x)
- {
- return Math.sin(1.1*x-0.3)/(2.5 + Math.pow(x, 2));
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- double a=0.4;
- double b=2.2;
- double wyn,h;
- int n ;
- Scanner el_wejsciowy =new Scanner(System.in);
- System.out.println("Podaj n");
- n=el_wejsciowy.nextInt();
- h=(b-a)/n;
- double [] x = new double[n+1];
- for (int i=0;i<x.length;i++)
- {
- x[i]= (a + (i*(b-a)/n));
- }
- double [] y = new double[n];
- for (int i=0;i<y.length;i++)
- {
- y[i]= (x[i] + x[i+1])/2;
- }
- wyn= 0;
- for(int i=0;i< x.length;i++)
- {
- if(i==(x.length-1))
- {
- wyn += caleczka(x[i]);
- }
- else {
- wyn += caleczka(x[i])*2;
- }
- }
- for (int i=0;i<y.length;i++)
- {
- wyn += caleczka(y[i])*4;
- }
- wyn *=(h/6);
- System.out.println("Calka wynosi:" + wyn);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement