⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 713.cpp

📁 理查森外推程序输入编号(1
💻 CPP
字号:
// 713.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include "math.h"
using std::cin;
using std::cout;
using std::endl;
using namespace std;



//definition three function P(h)=(1/2h)*[f(x+h)-f(x-h)]
double ln1(double h, int n)
{
	double t;
    h=h/pow(2,n);
	t=0.5*(log(3+h)-log(3-h))/h;
	return t;
}
double tan1(double h, int n)
{
	double t;
    h=h/pow(2,n);
	t=0.5*(tan(1.39401+h)-tan(1.39401-h))/h;
	return t;
}
double sin2(double x)
{
	double s;
	s=sin(pow(x,3)+x/3);
	return s;
}
double sin1(double h, int n)
{
	double t;
    h=h/pow(2,n);
	t=0.5*(sin2(1.39401+h)-sin2(1.39401-h))/h;
	return t;
}
//主函数
void main()
{
	int n,M,k,i;
	double h;
	cout<<"输入整数M=";
    cin>>M;
	cout<<"输入步长h=";
    cin>>h;
	typedef double *DoublePtr;
	DoublePtr *D=new DoublePtr[M+1];
	for(k=0;k<=M;k++)
		D[k]=new double[M+1];
	
	

cout<<"输入标题号i(1.ln(x) 2.tan(x) 3.sin(x^2+x/3))"<<endl;
cout<<"i=";
	cin>>i;
	//选择题号
	switch(i)
	{
	case 1:
      for(n=0;n<=M;n++)
	  {
		 D[n][0]=ln1(h,n);
	  }
	break;
	case 2:
        for(n=0;n<=M;n++)
	  {
		 D[n][0]=tan1(h,n);
	  }

	break;
	case 3:
        for(n=0;n<=M;n++)
	  {
		 D[n][0]=sin1(h,n);
	  }

	break;
	}
//理查森外推
  for(k=1;k<=M;k++)
  {
	  for(n=k;n<=M;n++)
	  {
		  D[n][k]=D[n][k-1]+(D[n][k-1]-D[n-1][k-1])/(pow(4,k)-1);
      }
  }

//输出数据 按照例6的格式
  cout<<"n ";
  for(k=0;k<=M;k++)
	  cout<<"D(n,"<<k<<")     ";
  cout<<endl;
  for(n=0;n<=M;n++)
  {
	  cout<<n<<" ";
      for(k=0;k<=n;k++)
	  {
		  cout<<showpoint<<fixed
			  <<setprecision(7)
			  <<D[n][k]<<" ";
	  }
	  cout<<endl;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -