Kudrashka JUL |
23-05-2012 17:32 1921157 |
Численное интегрирование. Метод трапеций.
Не получается реализовать данные метод в C++. Помогите,пожалуйста.
Код:
#include <stdlib.h>
#include <MATH.h>
#include <CONIO.h>
#include <iostream>
using namespace std;
float f(float);
float a;
float b;
float x;
float h;
float sum;
int n;
int i;
int main()
{
cout << "Input a = "; cin >> a;
cout << "Input b = "; cin >> b;
cout << "Input n = "; cin >> n;
h = (b - a) / n;
sum = (0.5 * h) * (f(a) + f(b));
cout <<"%f\n";
for (i = 1; i < n; i++) {
sum = sum + h * f(a + (i * h)); cout <<"%f\n";
}
cout << "The value of the integral is: %f\n";
}
float f(float x) {
float value;
value = exp(-(x*x));
return value;
}
|
Kudrashka JUL |
25-05-2012 21:05 1922654 |
спасибо большое
|
Время: 19:46.
© OSzone.net 2001-