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

📄 approach.cpp

📁 这是我编写的一些关于数值分析算法
💻 CPP
字号:
// Approach.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <math.h>
#include <iostream.h>
#define n 3

void Gauss(double a[n][n],double b[n]);

int main(int argc, char* argv[])
{
	double a[3][3]={{2,6,-4},{1,4,-5},{6,-1,18}};
    double b[3]={4,3,2};
	Gauss(a,b);
	for (int i=0;i<n;i++)
	{
		cout<<b[i]<<endl;
	}
	return 0;
}

void Gauss(double a[n][n],double b[n])
{
    double temp;
	for (int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			temp=a[j][i];
			for (int k=i;k<n;k++)
			{
				a[j][k]-=((a[i][k])*(temp/a[i][i]));
			}
				
			b[j]-=b[i]*(temp/a[i][i]);
		}
	}
	for(i=n-1;i>=0;i--)
	{
		temp=0;
		for(int j=i+1;j<=n-1;j++)
			temp+=a[i][j]*b[j];
		b[i]=(b[i]-temp)/a[i][i];
	}
}

⌨️ 快捷键说明

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