Calcul de la valeur approchée de l’intégrale d'une fonction entre 2 bornes en JAVA
par
, 28/12/2015 à 15h21 (2726 Affichages)
pour faire écho à un post précédent intitulé "Calcul de la valeur approchée de l’intégrale d'une fonction entre 2 bornes en JavaScript", voici le code source correspondant en JAVA :
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 public class Integrale { private double borneInf; private double borneSup; private int nbeInterval; private Fonction fonction; public Integrale(double a, double b, int n, Fonction f) { this.setBorneInf(a); this.setBorneSup(b); this.setNbeInterval(n); this.setFonction(f); } double f(double x) { return (x * x); } public double getBorneInf() { return borneInf; } public void setBorneInf(double borneInf) { this.borneInf = borneInf; } public double getBorneSup() { return borneSup; } public void setBorneSup(double borneSup) { this.borneSup = borneSup; } public int getNbeInterval() { return nbeInterval; } public void setNbeInterval(int nbeInterval) { this.nbeInterval = nbeInterval; } private double integraleInf() { double sommeInf = 0; double interval = (this.getBorneSup() - this.getBorneInf())/this.getNbeInterval(); for (int i = 0; i < this.getNbeInterval(); i++) { sommeInf += f(this.getBorneInf() + i * interval) * interval; } return sommeInf; } private double integraleSup() { double sommeSup = 0; double interval = (this.getBorneSup() - this.getBorneInf())/this.getNbeInterval(); for (int i = 1; i < (this.getNbeInterval() + 1); i++) { sommeSup += f(this.getBorneInf() + i * interval) * interval; } return sommeSup; } public double integraleMoyenne() { double res = (this.integraleSup() + this.integraleInf()) / 2; return res; } public Fonction getFonction() { return fonction; } public void setFonction(Fonction fonction) { this.fonction = fonction; } }