initial upload

This commit is contained in:
2024-09-10 20:25:18 +08:00
parent b8de03ee4f
commit f1cc876972
377 changed files with 2721267 additions and 34 deletions

View File

@@ -0,0 +1,39 @@
#include "iostream"
#include "iomanip"
#include "string.h"
#include "cmath"
using namespace std;
double func(double x)//积分函数
{
return pow(x,2);
}
double integration (double a,double b,double eps)//执行变步长梯形求积法
{
int n,k;
double fa,fb,h,t1,p,s,x,t;
fa=func (a); fb=func (b);
n=1; h=b-a;
t1=h*(fa+fb)/2.0;
p=eps+1.0;
while (p>=eps)
{
s=0.0;
for (k=0;k<=n-1;k++)
{
x=a+(k+0.5)*h;
s=s+func (x);
}
t=(t1+h*s)/2.0;
p=fabs(t1-t);
t1=t; n=n+n; h=h/2.0;
}
return t;
}
int main(int argc, char const *argv[])
{
cout<<integration(0,1,0.000001)<<endl;
return 0;
}

View File

@@ -0,0 +1,131 @@
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;
FILE *fout;
const double G=6.67191e-6; //万有引力常数
double density=2e+3; //密度(千克每立方米)
const double PI=3.1415926535897932;
double R=20; //圆柱体半径
double h=10; //圆柱体上顶埋深
double H=60; //圆柱体下底埋深
double x1,x2,y3,y2; //计算区域横坐标起始位置
double d; //计算区域网格间距
double x,y,X,l,M,N,L; //横,纵坐标,异常值
double Xo,Yo;
class ffts
{
private:
double a, b, eps, integ;
public:
ffts (double aa, double bb, double es)//顺序提供a,b,eps值的构造函数
{ a = aa; b = bb; eps = es; }
void integration (); //执行变步长梯形求积法
void output (); //输出积分值到文件并显示
double func (double); //计算被积函数值
};
void ffts::integration () //执行变步长梯形求积法
{
int n,k;
double fa,fb,h,t1,p,s,x,t;
fa=func (a); fb=func (b);
n=1; h=b-a;
t1=h*(fa+fb)/2.0;
p=eps+1.0;
while (p>=eps)
{
s=0.0;
for (k=0;k<=n-1;k++)
{
x=a+(k+0.5)*h;
s=s+func (x);
}
t=(t1+h*s)/2.0;
p=fabs(t1-t);
t1=t; n=n+n; h=h/2.0;
}
integ = t;
}
void ffts::output () //输出积分值到文件并显示
{
if((fout=fopen("yuanzhuti.dat","a"))==NULL)//可设置xls格式文件
{
cout<<"error!";
return;
}
if(X>R)
{
fprintf(fout,"%lf %lf %lf\n",x,y,integ*G*density);
printf("%lf %lf %lf\n",x,y,integ*G*density);//输出数据
fclose(fout);
}
else if(X==R)
{
fprintf(fout,"%lf %lf %lf\n",x,y,integ*G*density);
printf("%lf %lf %lf\n",x,y,integ*G*density);//输出数据
fclose(fout);
}
else if(X>0&&X<R)
{
fprintf(fout,"%lf %lf %lf\n",x,y,(integ+L)*G*density);
printf("%lf %lf %lf\n",x,y,(integ+L)*G*density);//输出数据
fclose(fout);
}
else if(X==0)
{
fprintf(fout,"%lf %lf %lf\n",x,y,G*density*2*PI*(sqrt(R*R+h*h)-sqrt(R*R+H*H)+H-h));
printf("%lf %lf %lf\n",x,y,G*density*2*PI*(sqrt(R*R+h*h)-sqrt(R*R+H*H)+H-h));//输出数据
fclose(fout);
}
}
double ffts::func (double l)
{
M=(1/sqrt(l*l+h*h)-1/sqrt(l*l+H*H));
N=2*l*acos((l*l+X*X-R*R)/(2*l*X));
if(X>R) return N*M;
else if(X==R) return (2*l*acos(l/(2*R)))*M;
else if(X>0&&X<R) return N*M;
return N*M;
}
int main()
{
printf("\nPlease input the calculating region and grid space : ");
scanf("%lf %lf %lf %lf %lf",&x1,&x2,&y3,&y2,&d);
Xo=100;
Yo=100;
for(x=x1;x<=x2;x+=d)
{
for(y=y3;y<=y2;y+=d)
{
X=(int)sqrt((x-Xo)*(x-Xo)+(y-Yo)*(y-Yo));
if(X>R)
{
ffts solution(X-R, X+R, 0.00001); //创建对象并顺序提供a, b, eps值
solution.integration (); //执行变步长梯形求积法
solution.output (); //输出积分值到文件并显示
}
else if(X==R)
{
ffts solution(0.0, 2*R, 0.00001); //创建对象并顺序提供a, b, eps值
solution.integration (); //执行变步长梯形求积法
solution.output (); //输出积分值到文件并显示
}
else if(X>0&&X<R)
{
L=2*PI*(sqrt((R-X)*(R-X)+h*h)-sqrt((R-X)*(R-X)+H*H)+H-h);
ffts solution(R-X, X+R, 0.00001); //创建对象并顺序提供a, b, eps值
solution.integration (); //执行变步长梯形求积法
solution.output (); //输出积分值到文件并显示
}
}
}
printf("\nCalculating completed!\n\nPlease press any key to exit ...");
return 0;
}