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

📄 高斯-勒让德求积法.cpp

📁 数值分析 求积分算法源码
💻 CPP
字号:
// 高斯-勒让德求积法.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <conio.h>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	//float a=0,b=2,e=0.000001;
	//float a=3.14159265/2,b=3.14159265*3/4,e=0.000001;
    float a=2,b=3,e=0.000001;
	float result;
	int point;
	float h = (b - a) / 2, c = (a + b) / 2;
	float y(float h,float x,float c),f(float x);

	cout<<"【高斯-勒让德求积法计算定积分】"<<endl<<endl;	
	cout<<" 请输入点数(3或5):";
	cin>>point;
	if(point==3)
	{
		result = h * (0.5555556*(f(y(h,-0.7745967,c))+f(y(h,0.7745967,c))) + f(y(h,0,c)));
		cout<<endl<<" 三点高斯-勒让德求积公式  运算结果是:"<<result<<endl;
	}
	if(point==5)
	{
		result = h * (0.2369269*(f(y(h,-0.9061798,c))+f(y(h,0.9061798,c))) + 0.4786287*(f(y(h,-0.5384693,c))+f(y(h,-0.5384693,c))) + 0.5688889*f(y(h,0,c)));
		cout<<"五点高斯-勒让德求积公式  运算结果是:"<<result<<endl;
	}
	cout<<endl<<"按任意键继续...";
	getch();
	return 0;
}
//用于将被积函数转换到[-1,1]区间
float y(float h,float x,float c)
{
	return h*x+c;
}
//积分函数
float f(float x)
{
	//return x*x*exp(-x*x);
	//return 1/tan(x);
    return 1/(x*x-1);

}

⌨️ 快捷键说明

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