-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherf.cpp
More file actions
72 lines (67 loc) · 1.42 KB
/
erf.cpp
File metadata and controls
72 lines (67 loc) · 1.42 KB
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
71
72
#include<iostream>
#include<cmath>
#include<fstream>
#include<math.h>
//funcion e^(-t^2)
float func(float x){
return exp(-pow(x,2));
}
// SimpsonINT
float simpson(float a, float b){
return (b-a)*(func(a)+4*func(0.5*(a+b))+func(b))/6;
}
float erf(float a, float h){
float integral=0;
if(a>0){
float x=-a;
float b=x+h;
while (x<a){
integral+=simpson(x,b);
x=b;
b+=h;
}
return (1/sqrt(M_PI))*integral;
}
else{
float x=-a;
float b=x-h;
while (x>a){
integral+=simpson(x,b);
x=b;
b-=h;
}
return (1/sqrt(M_PI))*integral;
}
}
float erf2(float b, float h){ //Solución de la ec.diferencial con método de Gauss
double y=0;
double a=0;
double v=2/sqrt(M_PI);
if(b>0){
while(a<b){
v=(1-2*a*h)*v;
y+=h*v;
a=a+h;
}
}
if(b<0){
while(a>b){
v=(1+2*a*h)*v;
y-=h*v;
a=a-h;
}
}
return y;
}
int main(){
std::cout << "Llevando a cabo la inegración" << std::endl;
for(int i =-3; i<4;i++){
std::cout << erf(i,0.001) << ",";
}
std::cout << std::endl;
std::cout << "Solucionando la ecuación diferencial" << std::endl;
for(int i =-3; i<4;i++){
std::cout << erf2(i,0.001) << ",";
}
std::cout << std::endl;
}