Fortran Coder

查看: 8705|回复: 5

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

[复制链接]

23

帖子

9

主题

0

精华

熟手

F 币
124 元
贡献
79 点
发表于 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

帖子

3

主题

0

精华

版主

F 币
1964 元
贡献
1677 点

帅哥勋章管理勋章爱心勋章新人勋章热心勋章元老勋章

发表于 2015-3-19 16:18:01 | 显示全部楼层
从你的代码来看,这个是CVF的工程,因为用到了IMSL,我帮不到你,但是从代码分析来讲,你这去掉注释解除后,代码应该没有问题。

709

帖子

4

主题

0

精华

大师

农村外出务工人员

F 币
596 元
贡献
305 点

新人勋章爱心勋章水王勋章元老勋章热心勋章

发表于 2015-3-19 17:22:57 | 显示全部楼层
错误提示很重要,为什么每次都不给出?

23

帖子

9

主题

0

精华

熟手

F 币
124 元
贡献
79 点
 楼主| 发表于 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)

非常感谢!!

709

帖子

4

主题

0

精华

大师

农村外出务工人员

F 币
596 元
贡献
305 点

新人勋章爱心勋章水王勋章元老勋章热心勋章

发表于 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


59

帖子

2

主题

0

精华

大师

F 币
810 元
贡献
476 点
发表于 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 



Example-of-using-NEQNF-subroutine.pdf

24.49 KB, 下载次数: 22

评分

参与人数 1F 币 +8 贡献 +8 收起 理由
fcode + 8 + 8 赞一个!

查看全部评分

您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-3-29 07:41

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表