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.trapezów;
- import java.util.Scanner;
- /**
- *
- * @author Student
- */
- public class MetodaTrapezów {
- 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));
- }
- wyn= 0;
- for(int i=0;i< x.length;i++)
- {
- if(i==0)
- {
- wyn += (caleczka(x[i])/2);
- }
- if(i==(x.length-1))
- {
- wyn += (caleczka(x[i])/2);
- }
- else {
- wyn += caleczka(x[i]);
- }
- }
- wyn *=h;
- System.out.println("Calka ta wynosi:" + wyn);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement