#include<iostream>
#include<cmath>
using namespace std;
int q;
int a; double b; double c;
double F(double x) {
cin >> q;
if (q == 1){
return 1 / (1 + sqrt(x));
}
else if(q == 2){
return 2 / (1 - 4 * x);
}
else {
return atan(x);
}
}
void defIntegral(double a, double b, int n) {
double x = a;
double dx = (b - a) / n;
double s, S = 0;
for (int i = 1; i <= n; i++) {
s = (F(x) + F(x + dx)) / 2 * dx;
S += s;
x += dx;
}
cout << S << endl;
}
int main() {
float accuracy;
cout << "which one:";
cin >> accuracy;
cout << "Точность" << endl;
if (q == a) {
defIntegral(0, 2, accuracy);
}
else if (q == b) {
defIntegral(-2, -1.2, accuracy);
}
else {
defIntegral(1.7, 0, accuracy);
}
return 0;
}
这是我在csdn上找到的关于矩阵的代码,并且修改了一下,但是题目里说(void defIntegral(double a, double b, int n) {
double x = a;
double dx = (b - a) / n;
double s, S = 0;)
这部分不能使用,因为这是通过矩形面积求积分,题目要求用梯形面积求积分。
你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答
本次提问扣除的有问必答次数,已经为您补发到账户,我们后续会持续优化,扩大我们的服务范围,为您带来更好地服务。