我正在尝试进行数值积分(使用子例程的矩形规则),这是我的代码,在我猜想(也许是)数据类型方面仍然存在一些问题,请帮助我完成代码并使之起作用使用。谢谢!
#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;
}
我正在尝试进行数值积分(使用子例程的矩形规则),这是我的代码,在我猜测(也许)涉及数据类型时仍然存在一些问题,请帮助我完成...]]] >