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

📄 diff.cpp

📁 对数学函数进行求导运算
💻 CPP
字号:
#include <iostream>
#include <math.h>
#include <fstream>
using namespace std;
const double PI=3.14159265358979323846;
double diff(double a,double b,double h);

int main()
{
	ofstream fout1;
	fout1.open("output.txt");
	fout1.setf(ios::fixed);
	fout1.setf(ios::showpoint);
	fout1.precision(10);
	if (fout1.fail())
	{
		cout<<"cannot open the file.";
		exit(1);
	}
    
	double a[10001],b[10000];
	double x=0;
	int i=0;
	for (i=0;i<10000;i++)
	{
		x=i*PI/10000.0;
		a[i]=sin(x);
		//fout1<<x<<"  "<<a[i]<<endl;
	}
	for (i=0;i<10000;i++)
	{
		if (9999==i)
		{
			a[10000]=0.0001*PI*diff(a[9998],a[9999],0.0001*PI)+a[9999];
		}
		b[i]=diff(a[i],a[i+1],0.0001*PI);
		fout1<<b[i]<<"  ";
		fout1<<cos(PI*i/10000.0)<<endl;
	}
	fout1.close();

	return 0;
}

double diff(double a,double b,double h)
{
	double c;
	c=(b-a)/h;
	return c;
}

⌨️ 快捷键说明

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