矩形规则(使用C ++进行数值积分

时间:2019-10-20 17:53:24

标签: c++ numeric subroutine numerical-integration

我正在尝试进行数值积分(使用子例程的矩形规则),这是我的代码,在我猜(也许)有关数据类型的问题上仍然存在一些问题,请帮助我完成代码并使其起作用要使用的。谢谢!

#include <iostream>
#include <string>
#include <cmath>
#include <conio.h>
#define Pi 3.142

using namespace std;
//Declaration of a subroutine to be used in Main

void Rect_Rule(int N, float x[],float H,float rect, float F[])
{


for (int i=1; i<=N; i++){
    F[i] = (x[i]*x[i]) * sin(x[i]) * exp(x[i]*x[i]);
    x[i] = x[i]+H;
    rect = (F[i]*H)+rect;

}

cout<< "Rectangular Rule= "<< rect << endl;

}

int main()
{   

float H ,sum, rect ;
int N;
cout << "Input the number of subsections" << endl;
cin >>N;
float F[N];
float x[N];

float UPLMT=Pi;
float LWRLMT=0.0;
H = (UPLMT-LWRLMT)/N;
x = LWRLMT;

Rect_Rule(N,x,H,rect,F);     
return 0;

}

0 个答案:

没有答案