-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExpDupla.cpp
executable file
·70 lines (67 loc) · 1.44 KB
/
ExpDupla.cpp
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
69
70
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<vector>
#include<limits>
#include<cmath>
using namespace std;
double senh(double x){
return ((exp(x) - exp(-x))/2);
}
double tangh(double x){
return((exp(x)-exp(-x))/(exp(x)+exp(-x)));
}
double cosh(double x){
return((exp(x)+exp(-x))/2);
}
double F(double x){
return 1/sqrt(x);
}
double gs(double a,double b,double s){
return F(((a+b)/2)+(((b-a)/2)*(tangh((3.1415/2)*senh(s)))))*(cosh(s)/pow(cosh((3.1415/2)*senh(s)),2));
}
double ExpDupla(double a, double b,double e){
double I=0,Iant,Iant2,N;
double deltax,inf,sup,x1,x2;
inf = -1;
sup = 1;
do{
N = 1;
Iant2 = I;
inf *= 1.1;
sup *= 1.1;
do{
Iant = I;
I = 0;
N *= 2;
deltax = (sup-inf)/N;
for(int p=0;p<N;p++){
x1 = inf + p*deltax;
x2 = x1 + deltax;
I = I + (deltax*(gs(a,b,x1) + gs(a,b,x2))/2);
}
I *= ((b-a)*3.1415/4);
}while(abs((I-Iant)/Iant)>=e);
}while(abs((I-Iant2)/Iant2)>=e);
return Iant2;
}
int main (int narg , char *argv[]){
double a,b,e;
int n,t=1;
do{
cout<<"Função a ser utilizada: 1/sqrt(x) "<<endl;
cout<<" "<<endl;
cout<<"Entre com o limite inferior do intervalo:"<<endl;
cin>>a;
cout<<"Entre com o limite superior do intervalo:"<<endl;
cin>>b;
cout<<"Entre com a precisao:"<<endl;
cin>>e;
cout<<"Integral: "<<ExpDupla(a,b,e)<<endl;
cout<<"Digite qualquer numero para recomecar ou 0 para sair"<<endl;
cin>>t;
}while(t!=0);
return 0;
}