需要完整的改写 以下 c++ 代码和 c#完整调用例子
每一个函数都要有,不要省略代码,谢谢
class NendToCSharp
{
private:
int N; //复系数多项式次数
Complex *c; //复系数多项式存储空间首地址
public:
NendToCSharp(void);
~NendToCSharp(void);
NendToCSharp(int nn=0, Complex *pp=NULL) //构造函数
{ N = nn; c = pp; }
template <class T>
int gauss(T *a, T *b, int n)
{
int *js,k,i,j,is,p,q;
double d,t;
T s;
js=new int[n];
for (k=0;k<=n-2;k++) //消元过程
{
d=0.0; //全选主元
for (i=k;i<=n-1;i++)
for (j=k;j<=n-1;j++)
{
t=ffabs(a[i*n+j]);
if (t>d) { d=t; js[k]=j; is=i;}
}
if (d+1.0==1.0) //系数矩阵奇异,求解失败!
{
for (i=0; i<n; i++) b[i] = init(s);
cout <<"系数矩阵奇异,求解失败!\n";
delete[]js;
return 0;
}
if (js[k]!=k) //列交换
{
for (i=0;i<=n-1;i++)
{
p=i*n+k; q=i*n+js[k];
s=a[p]; a[p]=a[q]; a[q]=s;
}
}
if (is!=k) //行交换
{
for (j=k;j<=n-1;j++)
{
p=k*n+j; q=is*n+j;
s=a[p]; a[p]=a[q]; a[q]=s;
}
s=b[k]; b[k]=b[is]; b[is]=s;
}
s=a[k*n+k];
for (j=k+1;j<=n-1;j++) //归一化
{
p=k*n+j; a[p]=a[p]/s;
}
b[k]=b[k]/s;
for (i=k+1;i<=n-1;i++) //消元
{
for (j=k+1;j<=n-1;j++)
{
p=i*n+j;
a[p]=a[p]-a[i*n+k]*a[k*n+j];
}
b[i]=b[i]-a[i*n+k]*b[k];
}
}
s=a[(n-1)*n+n-1];
if (ffabs(s)+1.0==1.0) //系数矩阵奇异,求解失败!
{
for (i=0; i<n; i++) b[i] = init(s);
cout <<"系数矩阵奇异,求解失败!\n";
delete[] js;
return 0;
}
b[n-1]=b[n-1]/s; //回代过程
for (i=n-2;i>=0;i--)
{
s=init(s);
for (j=i+1;j<=n-1;j++) s=s+a[i*n+j]*b[j];
b[i]=b[i]-s;
}
js[n-1]=n-1;
for (k=n-1;k>=0;k--) //恢复
if (js[k]!=k)
{
s=b[k]; b[k]=b[js[k]]; b[js[k]]=s;
}
delete[] js;
return 1;
}
template <class T> //模板声明T为类型参数
int gauss_jordan(T *a, T *b, int n)
{
int *js,k,i,j,is,p,q;
double d,t;
T s;
js=new int[n];
for (k=0;k<=n-1;k++) //消去过程
{
d=0.0; //全选主元
for (i=k;i<=n-1;i++)
for (j=k;j<=n-1;j++)
{
t=ffabs(a[i*n+j]);
if (t>d) { d=t; js[k]=j; is=i;}
}
if (d+1.0==1.0) //系数矩阵奇异,求解失败!
{
cout <<"系数矩阵奇异,求解失败!\n";
for (i=0; i<n; i++) b[i]=init(s);
delete[]js;
return 0;
}
if (js[k]!=k) //列交换
{
for (i=0;i<=n-1;i++)
{
p=i*n+k; q=i*n+js[k];
s=a[p]; a[p]=a[q]; a[q]=s;
}
}
if (is!=k) //行交换
{
for (j=k;j<=n-1;j++)
{
p=k*n+j; q=is*n+j;
s=a[p]; a[p]=a[q]; a[q]=s;
}
s=b[k]; b[k]=b[is]; b[is]=s;
}
s=a[k*n+k];
for (j=k+1;j<=n-1;j++) //归一化
{
p=k*n+j; a[p]=a[p]/s;
}
b[k]=b[k]/s;
for (i=0;i<=n-1;i++) //消元
{
if (i!=k)
{
for (j=k+1;j<=n-1;j++)
{
p=i*n+j;
a[p]=a[p]-a[i*n+k]*a[k*n+j];
}
b[i]=b[i]-a[i*n+k]*b[k];
}
}
}
for (k=n-1;k>=0;k--) //恢复
if (js[k]!=k)
{
s=b[k]; b[k]=b[js[k]]; b[js[k]]=s;
}
delete[] js;
return 1;
}
int trde(double b[], int n, int m, double d[])
{
int k,j;
double s;
if (m!=(3*n-2)) return -2;
for (k=0;k<=n-2;k++)
{
j=3*k; s=b[j];
if (fabs(s)+1.0==1.0) return 0;
b[j+1]=b[j+1]/s;
d[k]=d[k]/s;
b[j+3]=b[j+3]-b[j+2]*b[j+1];
d[k+1]=d[k+1]-b[j+2]*d[k];
}
s=b[3*n-3];
if (fabs(s)+1.0==1.0) return 0;
d[n-1]=d[n-1]/s;
for (k=n-2;k>=0;k--) d[k]=d[k]-b[3*k+1]*d[k+1];
return(2);
}
int band(double b[], double d[], int n, int l, int il, int m)
{
int ls,k,i,j,is,u,v;
double p,t;
if (il!=(2*l+1)) return(-2);
ls=l;
for (k=0;k<=n-2;k++)
{
p=0.0;
for (i=k;i<=ls;i++)
{
t=fabs(b[i*il]);
if (t>p) {p=t; is=i;}
}
if (p+1.0==1.0) return(0);
for (j=0;j<=m-1;j++)
{
u=k*m+j; v=is*m+j;
t=d[u]; d[u]=d[v]; d[v]=t;
}
for (j=0;j<=il-1;j++)
{
u=k*il+j; v=is*il+j;
t=b[u]; b[u]=b[v]; b[v]=t;
}
for (j=0;j<=m-1;j++)
{
u=k*m+j; d[u]=d[u]/b[k*il];
}
for (j=1;j<=il-1;j++)
{
u=k*il+j; b[u]=b[u]/b[k*il];
}
for (i=k+1;i<=ls;i++)
{
t=b[i*il];
for (j=0;j<=m-1;j++)
{
u=i*m+j; v=k*m+j; d[u]=d[u]-t*d[v];
}
for (j=1;j<=il-1;j++)
{
u=i*il+j; v=k*il+j; b[u-1]=b[u]-t*b[v];
}
u=i*il+il-1; b[u]=0.0;
}
if (ls!=(n-1)) ls=ls+1;
}
p=b[(n-1)*il];
if (fabs(p)+1.0==1.0) return(0);
for (j=0;j<=m-1;j++)
{
u=(n-1)*m+j; d[u]=d[u]/p;
}
ls=1;
for (i=n-2;i>=0;i--)
{
for (k=0;k<=m-1;k++)
{
u=i*m+k;
for (j=1;j<=ls;j++)
{
v=i*il+j; is=(i+j)*m+k;
d[u]=d[u]-b[v]*d[is];
}
}
if (ls!=(il-1)) ls=ls+1;
}
return(2);
}
int ldle(double a[], int n, int m, double c[])
{
int i,j,l,k,u,v,w,k1,k2,k3;
double p;
//省略
return(2);
}
int chlk(double a[], int n, int m, double d[])
{
int i,j,k,u,v;
if ((a[0]+1.0==1.0)||(a[0]<0.0)) return(0);
a[0]=sqrt(a[0]);
//省略
return(2);
}
int tlvs(double t[], int n, double b[], double x[])
{
int i,j,k;
double a,beta,q,c,h,*y,*s;
s=new double[n];
y=new double[n];
a=t[0];
//省略
return(1);
}
int seidel(double *a, double *b, int n, double *x, double eps)
{
int i,j,u,v;
double p,t,s,q;
//省略
return 1;
}
void grad(double a[],int n,double b[],double eps,double x[])
{
Matrix mx;
int i,k;
double *p,*r,*s,*q,alpha,beta,d,e;
p=new double[n];
r=new double[n];
s=new double[n];
q=new double[n];
for (i=0; i<=n-1; i++)
{ x[i]=0.0; p[i]=b[i]; r[i]=b[i]; }
i=0;
//省略
delete[] p; delete[] r; delete[] s; delete[] q;
return;
}
int maqr(double a[],int m,int n,double q[])
{
int i,j,k,l,nn,p,jj;
double u,alpha,w,t;
//省略
return 1;
}
int gmqr(double a[], int m, int n, double b[], double q[])
{
int i,j;
double d,*c;
c=new double[n];
i=maqr(a,m,n,q);
if (i==0)
{
delete[] c; return(0);
}
for (i=0; i<=n-1; i++)
{
d=0.0;
for (j=0; j<=m-1; j++) d=d+q[j*m+i]*b[j];
c[i]=d;
}
b[n-1]=c[n-1]/a[n*n-1];
for (i=n-2; i>=0; i--)
{
d=0.0;
for (j=i+1; j<=n-1; j++) d=d+a[i*n+j]*b[j];
b[i]=(c[i]-d)/a[i*n+i];
}
delete[] c; return(1);
}
int gmiv(double a[], int m, int n, double b[], double x[],
double aa[], double eps, double u[], double v[], int ka)
{
//省略
return(1);
}
int bingt(double a[], int n, double b[], double eps, double x[])
{
int i,j,k;
double q, qq;
double *p,*r,*e;
p=new double[n*n];
r=new double[n];
e=new double[n];
k=0;
//省略
delete[] p; delete[] r; delete[] e; return 1;
}
};