Answer the question
In order to leave comments, you need to log in
Why does the program loop (easy)?
Why is the program looping? Everything seems to be correct. The integral is considered by the trapezoid method with an accuracy of E=10^(-9).
#include "stdafx.h"
#include
#include
#include
using namespace std;
double f(double x)
{
return 2 * x / sqrt (1-x*x*x*x);
}
int _tmain(int argc, _TCHAR* argv[])
{
double a = 0, b = 0.9, n = 4, S = 0, h, integ, IntegPrev;
h = (b - a) / n;
for (int i = 1; i <= (n - 1); i++)
S += f(a + h*i);
integ = h * ((f(a) + f(b)) / 2 + S);
//calculate the first integral for n=4
do {
IntegPrev = integ;
n += 1;
h = (b - a) / n;
for (int i = 1; i <= (n - 1); i++)
S += f(a + h*i);
integ = h * ((f(a) + f(b)) / 2 + S);
} while (abs(IntegPrev - integ) > 0.000000001);
cout <<"qq" << integ;
getchar();
return 0;
}
Answer the question
In order to leave comments, you need to log in
for (int i = 1; i <= (n - 1); i++)
S += f(a + h*i);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question