主题:[讨论]请教高手关于程序运行的问题
有如下三段代码:
一:
#ifndef CONSTANTS_H
#define CONSTANTS_H
#include <math.h>
#define PI 3.14159
//Some constants and initial values
//double pi=3.1416;
double g=9.80665;
double roI=3990;
double roM=7000;
double roS=2543;
double sigmaMS=1375e-3;
double sigmaMI=1518e-3;
double sigmaIS=440e-3;
double myM=0.006;
double myS=0.1998;
//double myS=0.0399;
double AITA=1.0;
double XAITA=1.0;
double dI=20E-6;
double RI=dI/2;
double alfar1=(int)ceil(sigmaMS/((pow(RI,2))*g*(AITA*roM+2*roI)));
double betad1=(sqrt(g*pow(RI,3)))*(AITA*roM+2*roI)/myM;
double gammar1=(sqrt(g*pow(RI,3)))*(AITA*roM+2*roI)/myS;
double costhetaIMS=(sigmaMI-sigmaIS)/sigmaMS;
double NT=501;
double DT=0.0002;
double tEND=(NT-1)*DT;
double MN=3;
double MT=NT;
double JTIME=1;
double JJ=1;
double t0=0.0;
double Z0=0.0;
double V0=((2.0/9.0)*(pow(RI,2))*(roM-roI)*g)/(myM*sqrt(g*RI));
double S0=2e-3;
double S1=1e-3;
double ReI=roM*V0*sqrt(g*RI)*2*RI/myM;
double Jfig=0;
double JJflg=0;
#endif
二:
#include<iostream>
#include<math.h>
#include "constants.h"
using namespace std;
void CopyColumn(int n,int ColumnNumber,double **x,double *y)
//n-Array lenght
//ColumnNumber-number of the column to copy
//x-2d(n*m)input array
//y-result array
{
for(int i=0;i<n;i++)
y[i]=x[i][ColumnNumber];
//2d array menory allocation
/*
int n,m;
double **a;
n=5;//rows
m=6;//col
a=new double *[n];
for(int i=0;i<n;i++)
a[i]=new double[m];
*/
}
double z2(int k,double t,double *Y,int n)
{
//n must be initialized with some value
//n=50;
//n=3;
int F=1;
//k=0;
double AS,BS,C1,C2;
double Phai1=0.0;
double wmemb=0.0;
double P=0.0;
double Phai2=0.0;
double Phai3=0.0;
//Y=new double[n];
//Z=Y(:,1)
double Z=Y[0];
//V=Y(:,2)
double V=Y[1];
double PP=myM/myS;
double xmemb=0.0;
if(Z<1)
{
Phai1=(PP-1)*pow(Z,2)-2*(PP-1)*Z+PP;
}
else if(Z>=1)
{
Phai1=1;
}
P=roM/roS;
if(Z<2)
{
Phai2=0.25*(P-1)*pow(Z,3)-0.75*(P-1)*pow(Z,2)+P;
}
else
{
Phai2=1;
}
Phai3=Z-1-costhetaIMS;
AS=sigmaMS/((g*pow(RI,2))*(XAITA*roS*Phai2+2*roI));
BS=(sqrt(g*pow(RI,3))/myS)*(XAITA*roS*Phai2+2*roI);
C1=2*(roS*Phai2-roI)/(XAITA*roS*Phai2+2*roI);
C2=3*AS*Phai3;
if(k==1)
{
xmemb=V;
}
else if (k==2)
{
xmemb=C1-C2-(9*F*Phai1/BS)*V;
}
return xmemb;
}
void out1(double *arr,int n)
{
for(int i=0;i<n;i++)
{
//cout<<"{"<<arr[i]<<","<<" "<<arr[i+1]<<"}"<end1;
cout<<"{"<<arr[i]<<","<<" "<<arr[i+2]<<"}"<<endl;
}
}
void out2(double **arr,int n)
{
//int i=1;
int i;
int j;
for(i=0;i<n;i++)
{
//int j=2;
i=0;
for(j=0;j<30;j++)
cout<<"i0="<<"{"<<arr[i][j]<<"}"<<endl;
cout<<"BRAKE1"<<endl;
cout<<"BRAKE1"<<endl;
cout<<"BRAKE1"<<endl;
cout<<"BRAKE1"<<endl;
i=1;
for(j=0;j<30;j++)
cout<<"i1="<<"{"<<arr[i][j]<<"}"<<endl;
}
//for(i=1;i<n;i++)
// {
// for(j=0;j<4;j++)
// cout<<"i1="<<"{"<<arr[i][j]<<"}"<<end1;
// }
}
void out3(double *arr,int n)
{
for(int i=1;i<n;i++)
cout<<"res["<<i<<"]="<<" ";
cout<<endl;
}
int SaveToFile(int i0,int n,double *a,char *FileName)
{
FILE *f;
int m=n-i0;
if((f=fopen(FileName,"wb"))==NULL)
return -1;
fwrite(&m,sizeof(int),1,f);
for(int i=i0;i<n;i++)
fwrite(&a[i],sizeof(double),1,f);
fclose(f);
}
三:
#include<iostream>
#include<math.h>
#include "constants.h"
#include "functionsNofilm.cpp"
using namespace std;
int main(int argc,char *argv[])
{
double *Y0;
Y0=new double[3];
Y0[0]=Z0;
Y0[1]=V0;
Y0[3]=S0;
/*CALCULATION WITHOUT STEEL FLIM*/
int t=(int)ceil(t0+(JTIME-JJ)*DT);
int MXN=50;
double HROOT1=1.0-sqrt(0.5);//constant
double HROOT2=1.0+sqrt(0.5);
int N=3;
int i;
int x;
double *YW=new double[3];
YW=Y0;
double *Q4=new double[N];
for(i=0;i<N;i++)
{
Q4[i]=0;
}
int m=0;
int p=0;
int L=2;
int k;
double t1=0.0;
double t2=0.0;
double VF=1.0;
double VPP=myM/myS;
double VP=roM/roS;
double Vphai1=0.0;
double Vphai2=0.0;
double Vphai3=0.0;
double *K0=new double[L];
double *R1=new double[L];
double *Y1=new double[L];
double *Q1=new double[L];
double *K1=new double[L];
double *R2=new double[L];
double *Y2=new double[L];
double *Q2=new double[L];
double *K2=new double[L];
double *R3=new double[L];
double *Y3=new double[L];
double *Q3=new double[L];
double *K3=new double[L];
double *R4=new double[L];
double *Q5=new double[L];
double **Y4=new double*[L];
for(i=0;i<L;i++)
{
Y4[i]=new double[502];
for(int j=0;j<502;j++)
Y4[i][j]=0.0;
}
double *Z2=new double[501];
double *V2=new double[501];
double *alfa=new double[501];
double *AA2=new double[501];
double *BB2=new double[501];
double *CC2=new double[501];
double *Ff2=new double[501];
double *Fd2=new double[501];
double *Fr2=new double[501];
double *Fb2=new double[501];
double *TT2=new double[501];
while((JJflg==0)&&(p<MT-m))
{
p;
if(m==0)
t2=t0+(p-1)*DT;
else
t2=t1+p*DT;
TT2[p]=t2;
//out1(TT2,p);
for(k=0;k<L;k++)
{
K0[k]=DT*z2(k+1,t2,YW,MXN);
R1[k]=0.5*(K0[k]-2*Q4[k]);
Y1[k]=YW[k]+R1[k];
Q1[k]=Q4[k]+3*R1[k]-0.5*K0[k];
}
for(k=0;k<L;k++)
{
K1[k]=DT*z2(k+1,(t2+0.5*DT),Y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z2,"Z2.bin");
SaveToFile(0,size,Fr2,"Fr2.bin");
SaveToFile(0,size,Ff2,"Ff2.bin");
SaveToFile(0,size,Fb2,"Fb2.bin");
SaveToFile(0,size,Fd2,"Fd2.bin");
SaveToFile(0,size,TT2,"TT2.bin");
delete[]YW;
delete[]Q4;
delete[]K0;
delete[]R1;
delete[]Y1;
delete[]Q1;
delete[]K1;
delete[]R2;
delete[]Q2;
delete[]K2;
delete[]R3;
delete[]Y3;
delete[]Q3;
delete[]K3;
delete[]R4;
delete[]Y4;
delete[]Z2;
delete[]V2;
delete[]alfa;
delete[]AA2;
delete[]BB2;
delete[]CC2;
delete[]Ff2;
delete[]Fd2;
delete[]Fr2;
delete[]Fb2;
delete[]TT2;
system("PAUSE");
return EXIT_SUCCESS;
}
编译和链接都没事,但是运行主程序也就是第三个程序时,提示如下:
Debug Error!
Program:D:\Debug\main.exe
DAMAGE:after Nomal block(#51)at 0x001A1DC8.
(Press Retry to debug the application)
请问我应该怎么做才能得出结果?是要自己输入数据?还是要对哪些变量赋值?还是其他?敬请高手们不吝赐教,谢谢了!
一:
#ifndef CONSTANTS_H
#define CONSTANTS_H
#include <math.h>
#define PI 3.14159
//Some constants and initial values
//double pi=3.1416;
double g=9.80665;
double roI=3990;
double roM=7000;
double roS=2543;
double sigmaMS=1375e-3;
double sigmaMI=1518e-3;
double sigmaIS=440e-3;
double myM=0.006;
double myS=0.1998;
//double myS=0.0399;
double AITA=1.0;
double XAITA=1.0;
double dI=20E-6;
double RI=dI/2;
double alfar1=(int)ceil(sigmaMS/((pow(RI,2))*g*(AITA*roM+2*roI)));
double betad1=(sqrt(g*pow(RI,3)))*(AITA*roM+2*roI)/myM;
double gammar1=(sqrt(g*pow(RI,3)))*(AITA*roM+2*roI)/myS;
double costhetaIMS=(sigmaMI-sigmaIS)/sigmaMS;
double NT=501;
double DT=0.0002;
double tEND=(NT-1)*DT;
double MN=3;
double MT=NT;
double JTIME=1;
double JJ=1;
double t0=0.0;
double Z0=0.0;
double V0=((2.0/9.0)*(pow(RI,2))*(roM-roI)*g)/(myM*sqrt(g*RI));
double S0=2e-3;
double S1=1e-3;
double ReI=roM*V0*sqrt(g*RI)*2*RI/myM;
double Jfig=0;
double JJflg=0;
#endif
二:
#include<iostream>
#include<math.h>
#include "constants.h"
using namespace std;
void CopyColumn(int n,int ColumnNumber,double **x,double *y)
//n-Array lenght
//ColumnNumber-number of the column to copy
//x-2d(n*m)input array
//y-result array
{
for(int i=0;i<n;i++)
y[i]=x[i][ColumnNumber];
//2d array menory allocation
/*
int n,m;
double **a;
n=5;//rows
m=6;//col
a=new double *[n];
for(int i=0;i<n;i++)
a[i]=new double[m];
*/
}
double z2(int k,double t,double *Y,int n)
{
//n must be initialized with some value
//n=50;
//n=3;
int F=1;
//k=0;
double AS,BS,C1,C2;
double Phai1=0.0;
double wmemb=0.0;
double P=0.0;
double Phai2=0.0;
double Phai3=0.0;
//Y=new double[n];
//Z=Y(:,1)
double Z=Y[0];
//V=Y(:,2)
double V=Y[1];
double PP=myM/myS;
double xmemb=0.0;
if(Z<1)
{
Phai1=(PP-1)*pow(Z,2)-2*(PP-1)*Z+PP;
}
else if(Z>=1)
{
Phai1=1;
}
P=roM/roS;
if(Z<2)
{
Phai2=0.25*(P-1)*pow(Z,3)-0.75*(P-1)*pow(Z,2)+P;
}
else
{
Phai2=1;
}
Phai3=Z-1-costhetaIMS;
AS=sigmaMS/((g*pow(RI,2))*(XAITA*roS*Phai2+2*roI));
BS=(sqrt(g*pow(RI,3))/myS)*(XAITA*roS*Phai2+2*roI);
C1=2*(roS*Phai2-roI)/(XAITA*roS*Phai2+2*roI);
C2=3*AS*Phai3;
if(k==1)
{
xmemb=V;
}
else if (k==2)
{
xmemb=C1-C2-(9*F*Phai1/BS)*V;
}
return xmemb;
}
void out1(double *arr,int n)
{
for(int i=0;i<n;i++)
{
//cout<<"{"<<arr[i]<<","<<" "<<arr[i+1]<<"}"<end1;
cout<<"{"<<arr[i]<<","<<" "<<arr[i+2]<<"}"<<endl;
}
}
void out2(double **arr,int n)
{
//int i=1;
int i;
int j;
for(i=0;i<n;i++)
{
//int j=2;
i=0;
for(j=0;j<30;j++)
cout<<"i0="<<"{"<<arr[i][j]<<"}"<<endl;
cout<<"BRAKE1"<<endl;
cout<<"BRAKE1"<<endl;
cout<<"BRAKE1"<<endl;
cout<<"BRAKE1"<<endl;
i=1;
for(j=0;j<30;j++)
cout<<"i1="<<"{"<<arr[i][j]<<"}"<<endl;
}
//for(i=1;i<n;i++)
// {
// for(j=0;j<4;j++)
// cout<<"i1="<<"{"<<arr[i][j]<<"}"<<end1;
// }
}
void out3(double *arr,int n)
{
for(int i=1;i<n;i++)
cout<<"res["<<i<<"]="<<" ";
cout<<endl;
}
int SaveToFile(int i0,int n,double *a,char *FileName)
{
FILE *f;
int m=n-i0;
if((f=fopen(FileName,"wb"))==NULL)
return -1;
fwrite(&m,sizeof(int),1,f);
for(int i=i0;i<n;i++)
fwrite(&a[i],sizeof(double),1,f);
fclose(f);
}
三:
#include<iostream>
#include<math.h>
#include "constants.h"
#include "functionsNofilm.cpp"
using namespace std;
int main(int argc,char *argv[])
{
double *Y0;
Y0=new double[3];
Y0[0]=Z0;
Y0[1]=V0;
Y0[3]=S0;
/*CALCULATION WITHOUT STEEL FLIM*/
int t=(int)ceil(t0+(JTIME-JJ)*DT);
int MXN=50;
double HROOT1=1.0-sqrt(0.5);//constant
double HROOT2=1.0+sqrt(0.5);
int N=3;
int i;
int x;
double *YW=new double[3];
YW=Y0;
double *Q4=new double[N];
for(i=0;i<N;i++)
{
Q4[i]=0;
}
int m=0;
int p=0;
int L=2;
int k;
double t1=0.0;
double t2=0.0;
double VF=1.0;
double VPP=myM/myS;
double VP=roM/roS;
double Vphai1=0.0;
double Vphai2=0.0;
double Vphai3=0.0;
double *K0=new double[L];
double *R1=new double[L];
double *Y1=new double[L];
double *Q1=new double[L];
double *K1=new double[L];
double *R2=new double[L];
double *Y2=new double[L];
double *Q2=new double[L];
double *K2=new double[L];
double *R3=new double[L];
double *Y3=new double[L];
double *Q3=new double[L];
double *K3=new double[L];
double *R4=new double[L];
double *Q5=new double[L];
double **Y4=new double*[L];
for(i=0;i<L;i++)
{
Y4[i]=new double[502];
for(int j=0;j<502;j++)
Y4[i][j]=0.0;
}
double *Z2=new double[501];
double *V2=new double[501];
double *alfa=new double[501];
double *AA2=new double[501];
double *BB2=new double[501];
double *CC2=new double[501];
double *Ff2=new double[501];
double *Fd2=new double[501];
double *Fr2=new double[501];
double *Fb2=new double[501];
double *TT2=new double[501];
while((JJflg==0)&&(p<MT-m))
{
p;
if(m==0)
t2=t0+(p-1)*DT;
else
t2=t1+p*DT;
TT2[p]=t2;
//out1(TT2,p);
for(k=0;k<L;k++)
{
K0[k]=DT*z2(k+1,t2,YW,MXN);
R1[k]=0.5*(K0[k]-2*Q4[k]);
Y1[k]=YW[k]+R1[k];
Q1[k]=Q4[k]+3*R1[k]-0.5*K0[k];
}
for(k=0;k<L;k++)
{
K1[k]=DT*z2(k+1,(t2+0.5*DT),Y1,MXN);
R2[k]=HROOT1*(K1[k]-Q1[k]);
Y2[k]=Y1[k]+R2[k];
Q2[k]=Q1[k]+3*R2[k]-HROOT1*K1[k];
}
for(k=0;k<L;k++)
{
K2[k]=DT*z2(k+1,(t2+0.5*DT),Y2,MXN);
R3[k]=HROOT2*(K2[k]-Q2[k]);
Y3[k]=Y2[k]+R3[k];
Q3[k]=Q2[k]+3*R3[k]-HROOT2*K2[k];
}
for(k=0;k<L;k++)
{
K3[k]=DT*z2(k+1,(t2+DT),Y3,MXN);
R4[k]=(K3[k]-2*Q3[k])/6;
Y4[k][p+1]=Y3[k]+R4[k];
Q5[k]=Q3[k]+3*R4[k]-0.5*K3[k];
YW[k]=Y3[k]+R4[k];
}
Z2[p]=Y3[0]+R4[0];
V2[p]=Y3[1]+R4[1];
p=p+1;
}
for(k=0;k<(m+p);k++)
{
if(k==(m+p))
alfa[k]=(V2[k]-V2[k-1])/DT;
else
alfa[k]=(V2[k+1]-V2[k])/DT;
}
for(x=0;x<p;x++)
{
if(Z2[x]<1)
Vphai1=(VPP-1.0)*pow(Z2[x],2)-2*(VPP-1)*Z2[x]+VPP;
else
Vphai1=1.0;
AA2[x]=Vphai1;
if(Z2[2]<2.0)
Vphai2=0.25*(VP-1)*pow(Z2[x],3)-0.75*(VP-1)*pow(Z2[x],2)+VP;
else
Vphai2=1.0;
BB2[x]=Vphai2;
Vphai3=Z2[x]-1.0-costhetaIMS;
CC2[x]=Vphai3;
Ff2[x]=-(2.0/3.0)*PI*pow(RI,3)*((XAITA*roS*Vphai2+2*roI)*g*alfa[x]);//KOLLA HAR
Fd2[x]=-6*PI*RI*myS*VF*Vphai1*V2[x]*sqrt(RI*g);
Fr2[x]=-2*PI*RI*sigmaMS*Vphai3;
Fb2[x]=(4.0/3.0)*PI*pow(RI,3)*g*(roS*Vphai2-roI);
}
for(int j =0;j<501;j++)
{
TT2[j]*=sqrt(RI/g);
}
int size=501;
SaveToFile(0,size,V2,"V2.bin");
SaveToFile(0,size,Z2,"Z2.bin");
SaveToFile(0,size,Fr2,"Fr2.bin");
SaveToFile(0,size,Ff2,"Ff2.bin");
SaveToFile(0,size,Fb2,"Fb2.bin");
SaveToFile(0,size,Fd2,"Fd2.bin");
SaveToFile(0,size,TT2,"TT2.bin");
delete[]YW;
delete[]Q4;
delete[]K0;
delete[]R1;
delete[]Y1;
delete[]Q1;
delete[]K1;
delete[]R2;
delete[]Q2;
delete[]K2;
delete[]R3;
delete[]Y3;
delete[]Q3;
delete[]K3;
delete[]R4;
delete[]Y4;
delete[]Z2;
delete[]V2;
delete[]alfa;
delete[]AA2;
delete[]BB2;
delete[]CC2;
delete[]Ff2;
delete[]Fd2;
delete[]Fr2;
delete[]Fb2;
delete[]TT2;
system("PAUSE");
return EXIT_SUCCESS;
}
编译和链接都没事,但是运行主程序也就是第三个程序时,提示如下:
Debug Error!
Program:D:\Debug\main.exe
DAMAGE:after Nomal block(#51)at 0x001A1DC8.
(Press Retry to debug the application)
请问我应该怎么做才能得出结果?是要自己输入数据?还是要对哪些变量赋值?还是其他?敬请高手们不吝赐教,谢谢了!