-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLaplaceEquationSolver.c
More file actions
67 lines (50 loc) · 1005 Bytes
/
LaplaceEquationSolver.c
File metadata and controls
67 lines (50 loc) · 1005 Bytes
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
#include <stdio.h>
#include <math.h>
#define Kb 1.3806452e-23
#define Ni 1.05e16
#define Nd 1e24
double poisson(double x, double T){
double u;
u = Nd + Ni*exp(-x/(Kb*T)) - Ni*exp(x/(Kb*T));
return u;
}
int main()
{
FILE *ptr;
double T=300;
ptr = fopen("n.txt", "w");
for (double i = 1e-20; i <= 8e-20;)
{
fprintf(ptr, "%0.50lf %0.50lf\n", i, poisson(i,T));
i+=1e-22;
}
double p, b, d, e;
p = 0;
b = 1e-19;
while (1)
{
d = (p + b) / 2;
if (poisson(p,T) * poisson(d,T) < 0)
{
b = d;
}
else if (poisson(b,T) * poisson(d,T) < 0)
{
p = d;
}
e = (p + b) / 2;
if (poisson(p,T) * poisson(e,T) < 0)
{
b = e;
}
else if (poisson(b,T) * poisson(e,T) < 0)
{
p = e;
}
if (fabs(d - e) < 1e-24)
{
break;
}
}
printf("%e\n", e);
}