对分发迭代法牛顿法RKSRK方程.docx

上传人:b****5 文档编号:6060774 上传时间:2023-01-03 格式:DOCX 页数:15 大小:50.52KB
下载 相关 举报
对分发迭代法牛顿法RKSRK方程.docx_第1页
第1页 / 共15页
对分发迭代法牛顿法RKSRK方程.docx_第2页
第2页 / 共15页
对分发迭代法牛顿法RKSRK方程.docx_第3页
第3页 / 共15页
对分发迭代法牛顿法RKSRK方程.docx_第4页
第4页 / 共15页
对分发迭代法牛顿法RKSRK方程.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

对分发迭代法牛顿法RKSRK方程.docx

《对分发迭代法牛顿法RKSRK方程.docx》由会员分享,可在线阅读,更多相关《对分发迭代法牛顿法RKSRK方程.docx(15页珍藏版)》请在冰豆网上搜索。

对分发迭代法牛顿法RKSRK方程.docx

对分发迭代法牛顿法RKSRK方程

对分法SRK方程

#include

#include

#defineR8.314

floatfun(  floatA,  floatB, floatZ)

{

floatfz;

fz=pow(Z,3)-pow(Z,2)+(A-B-B*B)*Z-A*B;

returnfz;

}

main()

{

inti=1;

floatp0,t0,w,p1,t1,h,Z0,Z1,Z2;

floata,b,m,A,B,t2,at,y,y1,y2;

a=b=0.0;

printf("请输入临界参数:

\np0=");

scanf("%f",&p0);

printf("请输入临界参数:

\nt0=");

scanf("%f",&t0);

printf("请输入偏心因子:

\nw=");

scanf("%f",&w);

printf("请输入实际温度:

\nt1=");

scanf("%f",&t1);

printf("请输入实际压力:

\np1=");

scanf("%f",&p1);

m=0.480+1.574*w-0.176*w*w;

t2=t1/t0;

at=(1+m*(1-sqrt(t2)))*(1+m*(1-sqrt(t2)));

a=0.42748*R*R*pow(t0,2)/p0*at;

b=0.08664*R*t0/p0;

A=a*p1/(R*R*pow(t1,2));

B=b*p1/(R*t1);

Z1=0.0;Z2=3.0;

y1=fun(A,B,Z1);

y2=fun(A,B,Z2);

printf("第0次计算结果 y1=%.6f y2=%.6f Z1=%.5f Z2=%.5f\n",y1,y2,Z1,Z2);

do

{

Z0=(Z1+Z2)/2;

y=fun(A,B,Z0);

if(y>0)

{y2=y;Z2=Z0;}

if(y<0)

{y1=y;Z1=Z0;}

if(y=0)

{Z1=Z0;break;}

printf("第%-2d次计算结果 y1=%.6f y2=%.6f Z1=%.5f  Z2=%.5f\n",i,y1,y2,Z1,Z2);

i++;

}

while((fabs(Z1-Z2))>0.0001);

printf("\n");

printf("共经过%d次计算,求得压缩因子为Z=%.5f\n",--i,Z1);

 

}

对分法RK方程1

#include

#include

#defineR 8.314

#definet0126.2

#definep03394000.0

#definew 0.04

floatfun(  floatA,  floatB, floatZ)

{

floatfz;

fz=pow(Z,3)-pow(Z,2)+(A-B-B*B)*Z-A*B;

returnfz;

}

main()

{

inti=1;

floatp1,t1,Z0,Z1,Z2;

floata,b,A,B,t2,y,y1,y2;

a=b=0.0;

printf("氨的临界压力p0=%.1f\n",p0);

printf("氨的临界温度t0=%.1f\n",t0);

printf("氨的偏心因子 w=%.2f\n",w);

printf("请输入实际温度:

\nt1=");

scanf("%f",&t1);

printf("请输入实际压力:

\np1=");

scanf("%f",&p1);

a=0.42748*R*R*pow(t0,2)/p0;

b=0.08664*R*t0/p0;

A=a*p1/(R*R*pow(t1,2));

B=b*p1/(R*t1);

Z1=0.0;Z2=3.0;

y1=fun(A,B,Z1);

y2=fun(A,B,Z2);

printf("第0次计算结果 y1=%.6f y2=%.6f Z1=%.5f Z2=%.5f\n",y1,y2,Z1,Z2);

do

{

Z0=(Z1+Z2)/2;

y=fun(A,B,Z0);

if(y>0)

{y2=y;Z2=Z0;}

if(y<0)

{y1=y;Z1=Z0;}

if(y=0)

{Z1=Z0;break;}

printf("第%-2d次计算结果 y1=%.6f y2=%.6f Z1=%.5f  Z2=%.5f\n",i,y1,y2,Z1,Z2);

i++;

}

while((fabs(Z1-Z2))>0.0001);

printf("\n");

printf("共经过%d次计算,求得压缩因子为Z=%.5f\n",--i,Z1);

 

}

对分法RK方程2

#include

#include

#defineR8.314

#definet0126.2

#definep03394000.0

#definew 0.04

floatfun(  floatA,  floatB, floatZ)

{

floatfz;

fz=pow(Z,3)-pow(Z,2)+(A-B-B*B)*Z-A*B;

returnfz;

}

main()

{

inti=1;

floatp1,t1,h,Z0,Z1,Z2;

floata,b,m,A,B,t2,at,y,y1,y2;

a=b=0.0;

printf("氨的临界压力p0=%.1f\n",p0);

printf("氨的临界温度t0=%.1f\n",t0);

printf("氨的偏心因子 w=%.2f\n",w);

printf("请输入实际温度:

\nt1=");

scanf("%f",&t1);

printf("请输入实际压力:

\np1=");

scanf("%f",&p1);

m=0.480+1.574*w-0.176*w*w;

t2=t1/t0;

at=(1+m*(1-sqrt(t2)))*(1+m*(1-sqrt(t2)));

a=0.42748*R*R*pow(t0,2)/p0*at;

b=0.08664*R*t0/p0;

A=a*p1/(R*R*pow(t1,2));

B=b*p1/(R*t1);

Z1=0.0;Z2=3.0;

y1=fun(A,B,Z1);

y2=fun(A,B,Z2);

printf("第0次计算结果 y1=%.6f y2=%.6f Z1=%.5f Z2=%.5f\n",y1,y2,Z1,Z2);

do

{

Z0=(Z1+Z2)/2;

y=fun(A,B,Z0);

if(y>0)

{y2=y;Z2=Z0;}

if(y<0)

{y1=y;Z1=Z0;}

if(y=0)

{Z1=Z0;break;}

printf("第%-2d次计算结果 y1=%.6f y2=%.6f Z1=%.5f  Z2=%.5f\n",i,y1,y2,Z1,Z2);

i++;

}

while((fabs(Z1-Z2))>0.0001);

printf("\n");

printf("共经过%d次计算,求得压缩因子为Z=%.5f\n",--i,Z1);

 

}

迭代法RK方程

#include

#include

#defineR8.314

floatfun(  floatA,  floatB, floath)

{

floatZ;

Z=1.0/(1-h)-A/B*(h/(1+h));

returnZ;

}

main()

{

inti=1;

floatp0,t0,w,p1,t1,h,Z0;

floata,b,A,B,Z;

a=b=0.0;

printf("请输入临界参数:

\np0=");

scanf("%f",&p0);

printf("请输入临界参数:

\nt0=");

scanf("%f",&t0);

printf("请输入偏心因子:

\nw=");

scanf("%f",&w);

printf("请输入实际温度:

\nt1=");

scanf("%f",&t1);

printf("请输入实际压力:

\np1=");

scanf("%f",&p1);

a=0.42748*R*R*pow(t0,2.5)/p0;

b=0.08664*R*t0/p0;

A=a*p1/(R*R*pow(t1,2.5));

B=b*p1/(R*t1);

printf("请输入Z的迭代初值:

\nZ=");

scanf("%f",&Z);

do

{

Z0=Z;

h=B/Z0;

Z=fun(A,B,h);

printf("第%d次迭代 %f %f\n",i,Z,h);

i++;

}

while((fabs(Z-Z0))>0.0001);

printf("\n");

printf("共经过%d次迭代,求得压缩因子为w=%f\n",--i,Z);

}

迭代法SRK方程

#include

#include

#defineR8.314

floatfun(  floatA,  floatB, floath)

{

floatZ;

Z=1.0/(1-h)-A/B*(h/(1+h));

returnZ;

}

main()

{

inti=1;

floatp0,t0,w,p1,t1,h,Z0;

floata,b,m,A,B,Z,t2,ft;

a=b=0.0;

printf("请输入临界参数:

\np0=");

scanf("%f",&p0);

printf("请输入临界参数:

\nt0=");

scanf("%f",&t0);

printf("请输入偏心因子:

\nw=");

scanf("%f",&w);

printf("请输入实际温度:

\nt1=");

scanf("%f",&t1);

printf("请输入实际压力:

\np1=");

scanf("%f",&p1);

m=0.480+1.574*w-0.176*w*w;

t2=t1/t0;

ft=(1+m*(1-sqrt(t2)))*(1+m*(1-sqrt(t2)));

a=0.42748*R*R*pow(t0,2)/p0*ft;

b=0.08664*R*t0/p0;

A=a*p1/(R*R*pow(t1,2));

B=b*p1/(R*t1);

printf("请输入Z的迭代初值:

\nZ=");

scanf("%f",&Z);

h=B/Z;

printf("第0次迭代 %.4f %.5f\n",Z,h);

do

{

Z0=Z;

Z=fun(A,B,h);

h=B/Z;

printf("第%d次迭代 %.4f %.5f\n",i,Z,h);

i++;

}

while((fabs(Z-Z0))>0.0001);

printf("\n");

printf("共经过%d次迭代,求得压缩因子为w=%.4f\n",--i,Z);

}

牛顿迭代法RK方程

#include

#include

#defineR 8.314

#definet0126.2

#definep03394000.0

#definew 0.04

floatfun(  floatA,  floatB, floatZ)

{

floatfz;

fz=pow(Z,3)-pow(Z,2)+(A-B-B*B)*Z-A*B;

returnfz;

}

floatfun1(  floatA,  floatB, floatZ)

{

floatfz1;

fz1=3*pow(Z,2)-2*Z+(A-B-B*B);

returnfz1;

}

main()

{

inti=1;

floatp1,t1,Z0,Z1;

floata,b,A,B,t2,y,y1,y2;

a=b=0.0;

printf("氨的临界压力p0=%.1f\n",p0);

printf("氨的临界温度t0=%.1f\n",t0);

printf("氨的偏心因子 w=%.2f\n",w);

printf("请输入实际温度:

\nt1=");

scanf("%f",&t1);

printf("请输入实际压力:

\np1=");

scanf("%f",&p1);

printf("请输入牛顿迭代初值:

\nZ1=");

scanf("%f",&Z1);

a=0.42748*R*R*pow(t0,2.5)/p0;

b=0.08664*R*t0/p0;

A=a*p1/(R*R*pow(t1,2.5));

B=b*p1/(R*t1);

Z0=Z1;

do

{

Z1=Z0;

Z0=Z1-fun(A,B,Z1)/fun1(A,B,Z1);

printf("第%d次牛顿迭代 Z0=%f Z1=%f\n",i,Z0,Z1);

i++;

}

while(fabs(Z1-Z0)>0.0001);

printf("经过第%d次牛顿迭代,Z=%f\n",--i,Z0);

}

牛顿迭代法SRK方程

#include

#include

#defineR 8.314

#definet0126.2

#definep03394000.0

#definew 0.04

floatfun(  floatA,  floatB, floatZ)

{

floatfz;

fz=pow(Z,3)-pow(Z,2)+(A-B-B*B)*Z-A*B;

returnfz;

}

floatfun1(  floatA,  floatB, floatZ)

{

floatfz1;

fz1=3*pow(Z,2)-2*Z+(A-B-B*B);

returnfz1;

}

main()

{

inti=1;

floatp1,t1,Z0,Z1;

floata,b,m,A,B,t2,ft,y,y1,y2;

a=b=0.0;

printf("氨的临界压力p0=%.1f\n",p0);

printf("氨的临界温度t0=%.1f\n",t0);

printf("氨的偏心因子 w=%.2f\n",w);

printf("请输入实际温度:

\nt1=");

scanf("%f",&t1);

printf("请输入实际压力:

\np1=");

scanf("%f",&p1);

printf("请输入牛顿迭代初值:

\nZ1=");

scanf("%f",&Z1);

m=0.480+1.574*w-0.176*w*w;

t2=t1/t0;

ft=(1+m*(1-sqrt(t2)))*(1+m*(1-sqrt(t2)));

a=0.42748*R*R*pow(t0,2.5)/p0*ft;

b=0.08664*R*t0/p0;

A=a*p1/(R*R*pow(t1,2.5));

B=b*p1/(R*t1);

Z0=Z1;

do

{

Z1=Z0;

Z0=Z1-fun(A,B,Z1)/fun1(A,B,Z1);

printf("第%d次牛顿迭代 Z0=%f Z1=%f\n",i,Z0,Z1);

i++;

}

while(fabs(Z1-Z0)>0.0001);

printf("经过第%d次牛顿迭代,Z=%f\n",--i,Z0);

}

公式法SRK方程

#include

#include

#defineR8.314

#definet0126.2

#definep03394000.0

#definew 0.04

#definel (float)1/3

main()

{

inti=1;

floatp1,t1,D,U,V,Z,h,g;

floata,b,m,A,B,t2,at,q,p;

a=b=0.0;

printf("氨的临界压力p0=%.1f\n",p0);

printf("氨的临界温度t0=%.1f\n",t0);

printf("氨的偏心因子 w=%.2f\n",w);

printf("请输入实际温度:

\nt1=");

scanf("%f",&t1);

printf("请输入实际压力:

\np1=");

scanf("%f",&p1);

m=0.480+1.574*w-0.176*w*w;

t2=t1/t0;

at=(1+m*(1-sqrt(t2)))*(1+m*(1-sqrt(t2)));

a=0.42748*R*R*pow(t0,2)/p0*at;

b=0.08664*R*t0/p0;

A=a*p1/(R*R*pow(t1,2));

B=b*p1/(R*t1);

p=(3*(A-B-B*B)-1)/3;

q=(9*(A-B-B*B)-2-27*A*B)/27;

D=sqrt(q*q/4+p*p*p/27);

h=D-q/2;

g=-D-q/2;

U=pow(h,l);

V=pow(g,l);

Z=U+V;

printf("解出Z=%f\n",Z);

}

公式法SR方程

#include

#include

#defineR8.314

#definet0126.2

#definep03394000.0

#definew 0.04

#definel (float)1/3

main()

{

inti=1;

floatp1,t1,D,U,V,Z,h,g;

floata,b,m,A,B,t2,at,q,p;

a=b=0.0;

printf("氨的临界压力p0=%.1f\n",p0);

printf("氨的临界温度t0=%.1f\n",t0);

printf("氨的偏心因子 w=%.2f\n",w);

printf("请输入实际温度:

\nt1=");

scanf("%f",&t1);

printf("请输入实际压力:

\np1=");

scanf("%f",&p1);

a=0.42748*R*R*pow(t0,2.5)/p0;

b=0.08664*R*t0/p0;

A=a*p1/(R*R*pow(t1,2.5));

B=b*p1/(R*t1);

p=(3*(A-B-B*B)-1)/3;

q=(9*(A-B-B*B)-2-27*A*B)/27;

D=sqrt(q*q/4+p*p*p/27);

h=D-q/2;

g=-D-q/2;

U=pow(h,l);

V=pow(g,l);

Z=U+V;

printf("解出Z=%f\n",Z);

}

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > IT计算机 > 互联网

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1