用龙贝格方法,C语言高手进

来源:百度知道 编辑:UC知道 时间:2024/05/26 19:13:08
老师的题目是:用龙贝格方法上机计算
∫0-0.8 e-x2dx

要用C++程序编

// Romberg.cpp : Defines the entry point for the console application.
//
着就是C++的 不过有几个C函数罢了该一下啊!

#include "stdafx.h"
#include <iostream>
#include <math>
using namespace std;

const double e = 1.0E-8;
const double end = 1.0E-6;

//积分上下限
const double a = 0.0;
const double b = 0.8;

//被积函数
double function(long double x)
{
if(abs(x)<e) return 1.0;
else return pow(2.71828,x*x);
}

int min(int x, int y)
{
return x>y?y:x;
}

int main(int argc, char* argv[])
{
double * temp;
double * t = new double[1];
int m = 1;
int j = 0;
double h;
t[0] = (b-a)/2*(function(a)+function(b));//t_0[0]
while(true)
{
temp = new double[m];//创建数组temp[m]
int k = sizeof(double)*min(4,m);
::memcpy(temp,t,k);//将t数组的数拷到temp数组
delete []t;
t = new double