資源描述:
《有限元算例二維傳熱c程序源代碼.doc》由會(huì)員上傳分享,免費(fèi)在線(xiàn)閱讀,更多相關(guān)內(nèi)容在應(yīng)用文檔-天天文庫(kù)。
1、//------------計(jì)算多重積分的高斯方法------------------------//n整型變量,積分重?cái)?shù)//js整型一維數(shù)組,長(zhǎng)度為n,//其js(i)(i=0,1,...,n-1)表示第i層積分區(qū)間所劃分的子區(qū)間個(gè)數(shù)//fn()被積函數(shù)(函數(shù)指針)//fnGaussLimit()函數(shù)(函數(shù)指針)計(jì)算各層積分上下限值(上限>下限)//--------------------------------------------------------------doubleGaussIntegral(intn,int
2、js[],double(*fn)(intn,doublex[]),void(*fnGaussLimit)(intj,intn,doublex[],doubley[])){intm,j,k,q,*is;doubley[2],p,s,*x,*a,*b;staticdoublet[5]={-0.,-0.,0.0,0.,0.};staticdoublec[5]={0.,0.,0.,0.,0.};is=(int*)malloc(2*(n+1)*sizeof(int));x=(double*)malloc(n*sizeof(double))
3、;a=(double*)malloc(2*(n+1)*sizeof(double));b=(double*)malloc((n+1)*sizeof(double));m=1;a[n]=1.0;a[2*n+1]=1.0;while(true){for(j=m;j<=n;j++){fnGaussLimit(j-1,n,x,y);a[j-1]=0.5*(y[1]-y[0])/js[j-1];b[j-1]=a[j-1]+y[0];x[j-1]=a[j-1]*t[0]+b[j-1];a[n+j]=0.0;is[j-1]=1;is[n+j]
4、=1;}j=n;q=1;while(q==1){k=is[j-1];if(j==n)p=fn(n,x);elsep=1.0;a[n+j]=a[n+j+1]*a[j]*p*c[k-1]+a[n+j];is[j-1]=is[j-1]+1;if(is[j-1]>5){if(is[n+j]>=js[j-1]){j=j-1;q=1;if(j==0){s=a[n+1]*a[0];free(is);free(x);free(a);free(b);return(s);}}else{is[n+j]=is[n+j]+1;b[j-1]=b[j-1]+
5、a[j-1]*2.0;is[j-1]=1;k=is[j-1];x[j-1]=a[j-1]*t[k-1]+b[j-1];if(j==n)q=1;elseq=0;}}else{k=is[j-1];x[j-1]=a[j-1]*t[k-1]+b[j-1];if(j==n)q=1;elseq=0;}}m=j+1;}return0;}//--------------------------------------------------------------