It was necessary to develop a program for finding the value of a specific integral using the Gauss method. Function for integration and integration interval are shown below
Information on the Gauss method was taken from here:
http://ums.physics.usu.ru/st/num_03.pdf
http://aco.ifmo.ru/el_books/numerical_methods/lectures /glava2_3.html
y = cos (x) · (x +1) ^ - 1 + 2x
[1; 25]
# include & lt; iostream & gt;
#Include & lt; conio.h & gt;
#Include & lt; math.h & gt;
#Define N 3.
Using Namespace STD;
Double F (Double X)
{
RETURN COS (X) * (1./(x+1)) +2**;
}
Double Gauss (Double A, Double B)
{
Double xi [n] = { - 0.7745967,0,0,7745967};
Double Ci [n] = {0.5555556,0.8888889,0.5555556};
Double Ra = (B-A) / 2;
Double su = (a + b) / 2;
Double Q, S, I;
for (int i = 0; i & lt; n; i ++)
{
Q = SU + RA * XI [I - 1];
S = Ci [I - 1] * F (Q);
}
I = ra * s;
Return I;
}
INT MAIN ()
{
Double A;
Double B;
COUT & LT; & LT; "VVedite A" & lt; & lt; endl;
CIN & GT; & GT; A;
COUT & LT; & LT; "VVedite B" & lt; & lt; endl;
CIN & GT; & GT; B;
cout & lt; & lt; "i =" & lt; & lt; gauss (a, b);
Return 0;
}
An invalid response is displayed on 278.025, although Wolfram and other online calculators are calculating 623.7358
Answer 1, Authority 100%
Let’s start with the fact that in the cycle
for (int i = 0; i & lt; n; i ++)
{
Q = SU + RA * XI [I - 1];
S = Ci [I - 1] * F (Q);
}
What do you like xi [-1]
and ci [-1]
– well, when i = 0
?
Next – calculated for i = 0
and i = 1
values you just throw away. Generally. Why then do they even count them? 🙂
Next to ask or enough? 🙂
p.s. Just count on this range – [1; 25] – on all three points – quiet nonsense. Get something similar on the answer, but no more. Of course, not three times the difference, but … you need to break the entire interval for smaller segments, and only then on each smaller segment to use Gauss formula.
p.p.s. Okay, the pre-Christmas sale 🙂 Keep …
# include & lt; iostream & gt;
#Include & lt; conio.h & gt;
#Include & lt; math.h & gt;
Const int n = 3;
const int n = 100;
Using Namespace STD;
Double F (Double X)
{
RETURN COS (X) * (1./(x+1)) +2**;
}
Double Gauss (Double A, Double B)
{
const double xi [n] = { - 0.7745967,0,0,7745967};
const double ci [n] = {0.5555556,0.8888889,0.5555556};
Double Ra = (B-A) / 2;
Double su = (a + b) / 2;
Double Q, S = 0.0;
for (int i = 0; i & lt; n; i ++)
{
Q = SU + RA * XI [i];
S + = ci [i] * f (q);
}
RETURN RA * S;
}
INT MAIN ()
{
double a = 1.0;
Double B = 25.0;
Double S = 0.0;
for (int i = 0; i & lt; n; ++ i)
{
S + = Gauss (A + I * (B - A) / N, A + (I + 1) * (B - A) / N);
}
COUT & LT; & LT; "I =" & lt; & lt; S & LT; & LT; Endl;
Return 0;
}