Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package metoda.trapezów;
  7.  
  8. import java.util.Scanner;
  9.  
  10. /**
  11. *
  12. * @author Student
  13. */
  14. public class MetodaTrapezów {
  15.  
  16. public static double caleczka (double x)
  17. {
  18. return Math.sin(1.1*x-0.3)/(2.5 + Math.pow(x, 2));
  19.  
  20. }
  21. /**
  22. * @param args the command line arguments
  23. */
  24. public static void main(String[] args) {
  25. // TODO code application logic here
  26. double a=0.4;
  27. double b=2.2;
  28. double wyn,h;
  29. int n ;
  30.  
  31.  
  32. Scanner el_wejsciowy =new Scanner(System.in);
  33. System.out.println("Podaj n");
  34. n=el_wejsciowy.nextInt();
  35.  
  36. h=(b-a)/n;
  37.  
  38. double [] x = new double[n+1];
  39.  
  40. for (int i=0;i<x.length;i++)
  41. {
  42. x[i]= (a + (i*(b-a)/n));
  43. }
  44.  
  45. wyn= 0;
  46. for(int i=0;i< x.length;i++)
  47. {
  48. if(i==0)
  49. {
  50. wyn += (caleczka(x[i])/2);
  51. }
  52. if(i==(x.length-1))
  53. {
  54. wyn += (caleczka(x[i])/2);
  55. }
  56. else {
  57. wyn += caleczka(x[i]);
  58. }
  59. }
  60. wyn *=h;
  61. System.out.println("Calka ta wynosi:" + wyn);
  62.  
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement