📄 differential.h
字号:
#ifndef Differential_h
#define Differential_h
#include<iostream.h>
#include<math.h>
#include<stdlib.h>
#include<iomanip.h>
#include<fstream.h>
#define filename "initial.txt"
#define E 1.0e-8
double fabs(double x,double y){
double temp=x-y;
if(temp>=0)return temp;
else return -temp;
}
template<class Type> class Differential{
protected:
Type low,high,h,H,*u0,*t;int k,n,N;
Type (*u)(Type);
Type (*f)(Type,Type);
public:
Differential(Type (*pf)(Type,Type));
~Differential(){delete []u0;delete []t;}
Type U(Type t,Type (*u)(Type));
Type F(Type t,Type u,Type (*f)(Type,Type));
void Exact();//precision;
};
template<class Type> Differential<Type>::Differential(Type (*pf)(Type,Type)){
f=pf;
ifstream fin(filename,ios::in|ios::nocreate);
cout<<"Input low:";fin>>low;
cout<<"Input high:";fin>>high;
cout<<"Input h:";fin>>h;
fin.close();
H=high-low;N=int(H/h);
u0=new Type[N+1];
t=new Type[N+1];
for(int i=0;i<N+1;i++)
t[i]=low+i*h;
}
template<class Type> Type Differential<Type>::U(Type t,Type (*u)(Type)){//
return u(t);
}
template<class Type> Type Differential<Type>::F(Type t,Type u,Type (*f)(Type,Type)){//
return f(t,u);
}
template<class Type> void Differential<Type>::Exact(){
for(int i=0;i<N+1;i++)
{u0[i]=U(t[i],u);}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -