作业帮 > 综合 > 作业

龙贝格积分公式的Fortran程序代码

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/28 03:58:31
龙贝格积分公式的Fortran程序代码
用龙贝格求积算法计算下面的积分   只要有详细的过程和计算结果  不要Fortran程序也行  谢谢各位了
C++的行么?
Romberg.h:文件
// Romberg.h:interface for the Romberg class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_ROMBERG_H__3DC3390F_E15E_4BB7_98E5_64C7538BF4DD__INCLUDED_)
#define AFX_ROMBERG_H__3DC3390F_E15E_4BB7_98E5_64C7538BF4DD__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "afxtempl.h" //包含数组CArray模板
#include "math.h"
typedef double (*Fun)(double);
//Romberg算法
//方法取自《计算方法引论》(第二版)徐萃薇、孙绳武著 高等教育出版社 第119页
//但有改动,只使用了两个一维数组
//fun--被积函数的地址,[a,b]--积分区间,error--误差;
//count--计算次数,达到次数即使不满足精度也返回积分值,默认count=0--以误差为准
class CRomberg
{
public:
static double Romberg(Fun fun,double a,double b,double error,int count=0);
CRomberg();
virtual CRomberg();
};
#endif // !defined(AFX_ROMBERG_H__3DC3390F_E15E_4BB7_98E5_64C7538BF4DD__INCLUDED_)
Romberg.cpp:文件
// Romberg.cpp:implementation of the Romberg class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
//#include "NumericalMethods.h"
#include "Romberg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
typedef CArray CDoubleArray;
//在C++中可以直接使用fun(a)来表示C中的(*fun)(a)
//而不必定义下面的这个宏,这里只是明确一下:)
#define fun(a) (*fun)(a)
#define array1(a) (*array1)[a]
#define array0(a) (*array0)[a]
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CRomberg::CRomberg()
{
}
CRomberg::CRomberg()
{
}
//方法取自《计算方法引论》(第二版)徐萃薇、孙绳武著 高等教育出版社 第119页
//但有改动,只使用了两个一维数组
//fun--被积函数的地址,[a,b]--积分区间,error--误差;
//count--计算次数,达到次数即使不满足精度也返回积分值,默认countAdd(h*(fun(a)+fun(b)));
do
{
F=0.0f,m++;//注意m初值为0
for(i=1;iSetAtGrow(0,h*F+array0(0)/2);
w=4;
for(i=0;iSetAtGrow(i+1,(w*array1(i)-array0(i))/(w-1));
w