您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 有限元算例二维传热c++程序源代码8
//------------计算多重积分的高斯方法------------------------//n整型变量,积分重数//js整型一维数组,长度为n,//其js(i)(i=0,1,...,n-1)表示第i层积分区间所划分的子区间个数//fn()被积函数(函数指针)//fnGaussLimit()函数(函数指针)计算各层积分上下限值(上限下限)//--------------------------------------------------------------doubleGaussIntegral(intn,intjs[],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.9061798459,-0.5384693101,0.0,0.5384693101,0.9061798459};staticdoublec[5]={0.2369268851,0.4786286705,0.5688888889,0.4786286705,0.2369268851};is=(int*)malloc(2*(n+1)*sizeof(int));x=(double*)malloc(n*sizeof(double));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]=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]+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;}//--------------------------------------------------------------
本文标题:有限元算例二维传热c++程序源代码8
链接地址:https://www.777doc.com/doc-4536564 .html