数值积分之Romberg求积法

2024-06-06 15:38
文章标签 数值积分 romberg 求积

本文主要是介绍数值积分之Romberg求积法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

//Romberg求积法
#include <iostream>
#include <fstream>
#include <math.h>

using namespace std;

class romberg
{
private:
 int i, j, imax, jmax;
 double f, h, a, b, term1, term2, **I;

public:
 double func(double x)
 {
  f = exp(-x * x);
  return f;
 }
 void integral();
 ~romberg()
 {
  for (i = 0; i < imax; i++)
  {
   delete[] I[i];
  }
  delete[] I;
 }
};

void main()
{
 romberg integration;
 integration.integral();
}

void romberg::integral()
{
 imax = 5;
 jmax = 5;
 I = new double*[imax];
 for (i = 0; i < imax; i++)
 {
  I[i] = new double[jmax];
 }
 a = 0;
 b = 2;
 h = b - a;
 ofstream fout("romberg.txt");
 I[0][0] = (func(a) + func(b)) * h / 2;
 fout << I[0][0] << endl;
 for (i = 1; i < imax; i++)
 {
  I[i][0] = 0.0;
  term1 = h / pow(2.0, i);
  term2 = pow(2.0, i) - 1;
  for (j = 1; j <= term2; j += 2)
  {
   I[i][0] += func(a + j * term1);
  }
  I[i][0] = 0.5 * I[i-1][0] + term1 * I[i][0];
  fout << I[i][0] << endl;
 }
 for (j = 1; j < jmax; j++)
 {
  for (i = 0; i < (imax - j); i++)
  {
   I[i][j] = (pow(4.0, j) * I[i+1][j-1] - I[i][j-1]) / (pow(4.0, j) - 1);
   fout << I[i][j] << endl;
  }
 }
 fout.close();
}

这篇关于数值积分之Romberg求积法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1036522

相关文章

1071: 数据结构作业01 -- 一元多项式的求积

1071: 数据结构作业01 -- 一元多项式的求积 时间限制: 1 Sec   内存限制: 128 MB 提交: 48   解决: 8 [ 提交][ 状态][ 论坛] 题目描述 一个一元多项式可以看作由若干个一元单项式按降幂排列成的线性表。请编写程序对输入的两个一元多项式求积,并输出求积的结果。 输入 输入为两个一元多项式,每个一元多项式输入一行,按照降幂依次输入每个

数值积分之Simpson 3/8法则

//实现Simpson 3/8法则 #include <iostream> #include <math.h> using namespace std; class simpson2 { private:  int n, k;  double a, b, f, integral, interval, one_third_interval;  double sum_term1, sum_term

数值积分之Simpson 1/3法则

//实现Simpson 1/3法则 #include <iostream> #include <math.h> using namespace std; class simpson { private:  int n, k;  double a, b, f, half_interval, integral, interval, sum_even_terms;  double sum_odd_t

数值积分之Newton_Cotes闭合积分公式

//Newton_Cotes闭合积分公式 #include <iostream> #include <math.h> using namespace std; class trapezoidal { private:  int n, k;  double a, b, f, h, integral, sum; public:  double func(double v)  {   f = 24

【深耕 Python】Quantum Computing 量子计算机(6)计算<m|V|n>数值积分

写在前面 往期量子计算机博客: 【深耕 Python】Quantum Computing 量子计算机(1)图像绘制基础 【深耕 Python】Quantum Computing 量子计算机(2)绘制电子运动平面波 【深耕 Python】Quantum Computing 量子计算机(3)重要数学公式一览 【深耕 Python】Quantum Computing 量子计算机(4)量子物理概

计算方法实验9:Romberg积分求解速度、位移

任务 输出质点的轨迹 ( x ( t ) , y ( t ) ) , t ∈ { 0.1 , 0.2 , 0.3 , . . . , 10 } (x(t), y(t)), t\in \{0.1, 0.2, 0.3, ..., 10\} (x(t),y(t)),t∈{0.1,0.2,0.3,...,10},并在二维平面中画出该轨迹.请比较M分别取4, 8, 12, 16, 20 时,Rombe

数值分析复习:Richardson外推和Romberg算法

文章目录 Richardson外推Romberg(龙贝格)算法 本篇文章适合个人复习翻阅,不建议新手入门使用 本专栏:数值分析复习 的前置知识主要有:数学分析、高等代数、泛函分析 本节继续考虑数值积分问题 Richardson外推 命题:复合梯形公式的另一形式 设 f ∈ C ∞ [ a , b ] f\in C^{\infty}[a,b] f∈C∞[a,b],记

MATLAB:函数与数值积分

一、数学函数图像的绘制 clc,clearfh = @(x)2*exp(-x).*sin(x);Xrange = [0,8];gx = @(x)3*exp(-x)*0.8.*sin(x);fplot(fh,Xrange,'r-*','LineWidth',1.5)hold ongrid on fplot(gx,Xrange,'b-o','LineWidth',1.5)axis

POJ 2098 数值积分

#include <cstdio>#include <cstring>#include <cmath>#include <iostream>const double eps = 1E-6;int T;double a, b, l, r;// simpson公式用到的函数double F(double x){return sqrt(b * b * (1 - x * x / (a *