-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumcalu.hpp
More file actions
34 lines (30 loc) · 785 Bytes
/
numcalu.hpp
File metadata and controls
34 lines (30 loc) · 785 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
#pragma once
#include "scmath.h"
class numcalu
{
public:
static double solve(double a, double b, BasicNode* f, int n=1000)
{
double c;
for (int i = 0; i < n; i++)
{
c = (a + b) / 2;
if (scmath::caluExp(f,"x",c) == 0)
return c;
else if (scmath::caluExp(f,"x",c)*scmath::caluExp(f,"x",a) > 0) //选择异号的一边
a = c;
else
b = c;
}
return c;
}
static double integ(double lower, double upper, BasicNode* f, double accuracy = 0.1)
{
double result = 0;
for (; lower <= upper; lower += accuracy)
{
result += scmath::caluExp(f,"x",lower)*accuracy;
}
return result;
}
};