190
IntTR = IntTR + F(A + i * h) * h
Next i
IntTR = IntTR + (F(A) + F(B)) / 2 * h
n = n * 2
h = h / 2
Wend
ActiveSheet.Cells(10, 1).Value = "По методу трапеций = " & Str(IntTR)
n = ActiveSheet.Cells(2, 4).Value
h = (B - A) / n
IntPR = 0
IntPR3 = 100
While Abs(IntPR - IntPR3) > e
IntPR3 = IntPR
IntPR = 0
IntPR1 = 0
For i = 1 To n - 1 Step 2
IntPR1 = IntPR1 + F(A + i * h)
Next i
IntPR2 = 0
For i = 2 To n - 2 Step 2
IntPR2 = IntPR2 + F(A + i * h)
Next i
IntPR = h / 3 * (F(A) + F(B) + 4 * IntPR1 + 2 * IntPR2)
n = n * 2
h = h / 2
Wend
ActiveSheet.Cells(11, 1).Value = "По методу парабол = " & Str(IntPR)
EndSub
Решение в Microsoft Visual Studio
КодпрограммыС++:
// pr1 INTEGRAL ekonom.cpp: определяетточкувходадляконсольногоприложения.
//
#include
"stdafx.h"
#include
<iostream>
#include
<math.h>
usingnamespace
std;
double
a=0, b=8, n=8, h=(b-a)/n;
double
f(
double
t){
return
-0.2*pow(t,2.0)+1.6*t+3.0;
}
void
prav(){
double
integral=0, t;
for
(t=a+h; t<=b; t=t+h){
integral=integral+f(t);
}
integral=integral*h;
cout<<
"integral prav="
<<integral<<endl;
}
void
lev(){
double
integral=0, t;
for
(t=a; t<=b-h; t=t+h){
integral=integral+f(t);
}
integral=integral*h;
cout<<
"integral lev="
<<integral<<endl;