﻿ DNEQNF 算法求解非线性方程组-Fortran算法研究-专业Fortran论坛 -

# [非线性] DNEQNF 算法求解非线性方程组

23帖子 0精华  F 币
118 元 贡献
76 点 发表于 2015-3-19 16:09:43 | 显示全部楼层 |阅读模式
 大家好，我采用DNEQNF求解非线性方程组，代码如下： [Fortran] 纯文本查看 复制代码```C module function_equation C implicit none C contains subroutine FCN(xx,yy,nn) implicit none integer nn double precision xx(nn),yy(nn) yy(1) = xx(1)**2+xx(2)**2-5d0 yy(2) = (xx(1)+1d0)*xx(2)-(3d0*xx(1)+1d0) return end subroutine C end module program main_test use imsl C use function_equation implicit none external FCN double precision , parameter :: errrel = 1d-7 integer , parameter :: n = 2 integer , parameter :: itmax = 200 double precision x_guess,ans(2),fnorm x_guess = (1d0,1d0) call dneqnf(FCN,errrel,n,itmax,x_guess,ans,fnorm) print *, ans end ``` 如果希望将求解的方程封装在一个module里面，则出现错误。这样的问题应该怎么解决呢？ （上述代码去掉注释后 ，就将求解的函数封装在module里面了。）

136帖子 0精华  F 币
1453 元 贡献
1169 点       发表于 2015-3-19 16:18:01 | 显示全部楼层
 从你的代码来看，这个是CVF的工程，因为用到了IMSL，我帮不到你，但是从代码分析来讲，你这去掉注释解除后，代码应该没有问题。

615帖子 0精华  F 币
326 元 贡献
102 点     发表于 2015-3-19 17:22:57 | 显示全部楼层
 错误提示很重要，为什么每次都不给出？ 23帖子 0精华  F 币
118 元 贡献
76 点 楼主| 发表于 2015-3-20 09:56:18 | 显示全部楼层
 楚香饭 发表于 2015-3-19 17:22 错误提示很重要，为什么每次都不给出？ 你好 ，这个是提示信息。 D:\Fortran\Algorithm\nonliner_equation_03\main_test.for D:\Fortran\Algorithm\nonliner_equation_03\main_test.for(22) : Error: The attributes of this name conflict with those made accessible by a USE statement.   [FCN] external FCN -----------------^ D:\Fortran\Algorithm\nonliner_equation_03\main_test.for(29) : Error: The characteristics of dummy argument 1 of the associated actual procedure differ from the characteristics of dummy argument 1 of the dummy procedure. (12.2)   [FCN] call dneqnf(FCN,errrel,n,itmax,x_guess,ans,fnorm) --------------------^ D:\Fortran\Algorithm\nonliner_equation_03\main_test.for(29) : Error: The characteristics of dummy argument 2 of the associated actual procedure differ from the characteristics of dummy argument 2 of the dummy procedure. (12.2)   [FCN] call dneqnf(FCN,errrel,n,itmax,x_guess,ans,fnorm) --------------------^ Error executing df.exe. main_test.obj - 3 error(s), 0 warning(s) 非常感谢！！

615帖子 0精华  F 币
326 元 贡献
102 点     发表于 2015-3-20 13:21:20 | 显示全部楼层
 用 Module 封装，你得调用 F90 接口，F77接口不行 [Fortran] 纯文本查看 复制代码```Module function_equation contains Subroutine fcn(xx, yy, nn) Implicit None Integer nn Double Precision xx(nn), yy(nn) yy(1) = xx(1)**2 + xx(2)**2 - 5D0 yy(2) = (xx(1)+1D0)*xx(2) - (3D0*xx(1)+1D0) End Subroutine fcn End Module function_equation Program main_test Use neqnf_int Use umach_int Use function_equation Implicit None Double Precision, Parameter :: errrel = 1D-7 Integer, Parameter :: n = 2 Integer, Parameter :: itmax = 200 Double Precision x_guess(2), ans(2), fnorm x_guess = (1D0, 1D0) Call neqnf(fcn, ans, xguess=x_guess, fnorm=fnorm) Print *, ans End Program main_test``` 57帖子 0精华  F 币
731 元 贡献
445 点 发表于 2015-3-20 15:36:26 | 显示全部楼层
 Example of using NEQNF subroutine Example Statement Consider a binary system of component 1 and 2, with component 1 being the more volatile one. For a given pressure P and a vapor composition y of component 1 the dew point calculation consist in determining the Temperature T and the liquid composition x. Assuming ideal phase equilibrium the Pressure and the liquid composition are given by: The pressure should be in mmHg and temperature in oK. ---------------------------------------------------------------------------------------------------------------------------- Fortran Program Listing [Fortran] 纯文本查看 复制代码``` INTEGER N,ITMAX REAL X(3), XG(3), FNORM EXTERNAL FCN N=2 ERRREL=1.0e-4 ITMAX=100 XG(1)=0.5 XG(2)=100.0 call NEQNF (FCN, ERRREL, N, ITMAX, XG, X, FNORM) WRITE(6,*) WRITE(6,*)'FNORM = ',FNORM WRITE(6,*)'X1 = ',X(1) WRITE(6,*)'X2 = ',X(2) STOP END SUBROUTINE FCN(X,F,N) INTEGER N REAL X(N),F(N) P=3.0*750.6 Y=0.6 A1=19.6664 B1=-4361.55 A2=20.1735 B2=-5050.5 PS1=EXP(A1+B1/(X(2)+273)) PS2=EXP(A2+B2/(X(2)+273)) F(1)=P-X(1)*PS1-(1-X(1))*PS2 F(2)=Y*P-X(1)*PS1 RETURN END C Output C FNORM = 5.483037E-04 C X1 = 2.966535E-01 C X2 = 114.950700 C Stop - Program terminated. C Press any key to continue ``` 24.49 KB, 下载次数: 11

### 评分 fcode + 8 + 8 赞一个!

 本版积分规则 回帖后跳转到最后一页

GMT+8, 2019-5-19 17:09

Powered by Discuz! X3.2

© 2001-2017 Comsenz Inc.