Fortran Coder

查看: 18629|回复: 4
打印 上一主题 下一主题

[求助] 求解嵌套非线性方程组,改程序,求助

[复制链接]

17

帖子

5

主题

0

精华

入门

F 币
86 元
贡献
52 点
跳转到指定楼层
楼主
发表于 2014-4-26 12:15:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我要求A1,A3,可是只有含有A1,A3的表达式A,B,C,D的关系式,编程如下,求大师指导
[Fortran] 纯文本查看 复制代码
01program tu2
02use IMSL
03implicit none
04external FCN
05real*8 FCN
06real,parameter::ERRREL=0.0001
07integer,parameter::N=2
08integer,parameter::ITMAX=100
09real*8::XGUESS(N)=(/0.0467,0.0732/)
10real X(N),FNORM
11real*8 A1,A2,A3,A,B,C,D
12real*8 Z0,Zi
13real*8 E,F
14real,parameter::pi=3.14159
15integer,parameter::Zrs=5
16integer,parameter::A4s=9
17integer k,i
18real*8::Zr(Zrs)=(/1.0,2.0,3.0,4.0,5.0/)
19real*8::A4(A4s)=(/0.075,0.10,0.15,0.20,0.25,0.30,0.35,0.40,0.425/)
20common /group2/ zi
21common /group3/ A2
22!!**************************************************
23Zi=-3.0                  !!天线阻抗虚部的值
24Z0=50.0                  !!传输线的特性阻抗
25A2=0.25                  !!第二个支节的长度
26!!***************************************************
27do i=1,Zrs
28do k=1,A4s
29call  NEQNF(Zr(i),A4(k),FCN(i,k),ERRREL,N,ITMAX,XGUESS,X,FNORM)
30write(*,*) X
31stop
32end
33!!!**************************
34subroutine A4_get_A(A4,A)
35implicit none
36real*8 A2,A3,A4,A
37real,parameter::pi=3.14159
38common /group3/ A2
39A=cos(2.0*pi*A2)*cos(2.0*pi*A4)-sin(2.0*pi*A2)*(-cos(2.0*pi*A4)/tan(2.0*pi*A3)+sin(2.0*pi*A4))              !!A的函数式
40 
41return
42end
43!!!***************************
44subroutine A4_get_B(A4,B)
45implicit none
46real*8 A2,A3,A4,z0,B
47real,parameter::pi=3.14159
48common /group3/ A2
49common /group1/ Z0
50B=Z0*(cos(2.0*pi*A2)*sin(2.0*pi*A4)+sin(2.0*pi*A2)*(sin(2.0*pi*A4)/tan(2.0*pi*A3)+cos(2.0*pi*A4)))            !!B的函数式
51return
52end
53!!*****************************
54subroutine A4_get_C(A4,C)
55implicit none
56real*8 A1,A2,A3,A4,Z0,C
57real,parameter::pi=3.14159
58common /group3/ A2
59common /group1/ Z0
60C=1.0/Z0*(cos(2.0*pi*A4)*((-cos(2.0*pi*A2))/tan(2.0*pi*A1)+sin(2.0*pi*A2))+(sin(2.0*pi*A2)/tan(2.0*pi*A1)+cos(2.0*pi*A2))*((-cos(2.0*pi*A4))/tan(2.0*pi*A3)+sin(2.0*pi*A4)))
61return
62end
63!!*******************************
64subroutine A4_get_D(A4,D)
65implicit none
66real*8 A1,A2,A3,A4,D
67real,parameter::pi=3.14159
68 
69common /group3/ A2
70D=-sin(2.0*pi*A4)*(-cos(2.0*pi*A2)/tan(2.0*pi*A1)+sin(2.0*pi*A2))+(sin(2.0*pi*A2)/tan(2.0*pi*A1)+cos(2.0*pi*A2))*(sin(2.0*pi*A4)/tan(2.0*pi*A3)+cos(2.0*pi*A4))
71return
72end
73!!****************************************************
74 
75subroutine FCN(A,B,C,D,A4,Zr,XA,F,N)
76implicit none
77integer N
78real,target::XA(N)
79real F(N)
80real,pointer::A1,A3
81real*8 A,B,C,D,A4,Z0,Zr,Zi
82common /group1/Z0
83common /group2/Zi
84 
85A1=>XA(1)
86A3=>XA(2)
87call A4_get_A(A4,A)
88call A4_get_B(A4,B)
89call A4_get_C(A4,C)
90call A4_get_D(A4,D)
91 
92F(1)=A*D+B*C-Z0*((D-C*Zi)*(D-C*Zi)+(C*Zr)*(C*Zr))
93F(2)=(D*A-B*C)*Zi-A*C*(Zr*Zr+Zi*Zi)+D*B
94return
95end

以下是错误指示
Compiling Fortran...
C:\Program Files\Microsoft Visual Studio\MyProjects\tu2\tu2.f90
C:\Program Files\Microsoft Visual Studio\MyProjects\tu2\tu2.f90(29) : Error: The number of actual arguments cannot be greater than the number of dummy arguments.   [NEQNF]
call  NEQNF(Zr(i),A4(k),FCN(i,k),ERRREL,N,ITMAX,XGUESS,X,FNORM)
------^
C:\Program Files\Microsoft Visual Studio\MyProjects\tu2\tu2.f90(29) : Error: The type of the actual argument differs from the type of the dummy argument.   [A4]
call  NEQNF(Zr(i),A4(k),FCN(i,k),ERRREL,N,ITMAX,XGUESS,X,FNORM)
------------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\tu2\tu2.f90(29) : Error: The type of the actual argument differs from the type of the dummy argument.   [FCN]
call  NEQNF(Zr(i),A4(k),FCN(i,k),ERRREL,N,ITMAX,XGUESS,X,FNORM)
------------------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\tu2\tu2.f90(29) : Error: The type of the actual argument differs from the type of the dummy argument.   [0.0001]
call  NEQNF(Zr(i),A4(k),FCN(i,k),ERRREL,N,ITMAX,XGUESS,X,FNORM)
---------------------------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\tu2\tu2.f90(29) : Error: The type of the actual argument differs from the type of the dummy argument.   [2]
call  NEQNF(Zr(i),A4(k),FCN(i,k),ERRREL,N,ITMAX,XGUESS,X,FNORM)
----------------------------------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\tu2\tu2.f90(29) : Error: The type of the actual argument differs from the type of the dummy argument.   [100]
call  NEQNF(Zr(i),A4(k),FCN(i,k),ERRREL,N,ITMAX,XGUESS,X,FNORM)
------------------------------------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\tu2\tu2.f90(29) : Error: The type of the actual argument differs from the type of the dummy argument.   [XGUESS]
call  NEQNF(Zr(i),A4(k),FCN(i,k),ERRREL,N,ITMAX,XGUESS,X,FNORM)
------------------------------------------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\tu2\tu2.f90(29) : Error: This actual argument must be the name of a user subroutine or the name of intrinsic subroutine.   [ZR]
call  NEQNF(Zr(i),A4(k),FCN(i,k),ERRREL,N,ITMAX,XGUESS,X,FNORM)
------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\tu2\tu2.f90(29) : Error: The shape matching rules of actual arguments and dummy arguments have been violated.   [XGUESS]
call  NEQNF(Zr(i),A4(k),FCN(i,k),ERRREL,N,ITMAX,XGUESS,X,FNORM)
------------------------------------------------^
C:\Program Files\Microsoft Visual Studio\MyProjects\tu2\tu2.f90(28) : Error: An unterminated block exists.
do k=1,A4s
^
C:\Program Files\Microsoft Visual Studio\MyProjects\tu2\tu2.f90(27) : Error: An unterminated block exists.
do i=1,Zrs
^
Error executing df.exe.

tu2.obj - 11 error(s), 0 warning(s)

在此谢过!!
分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

2038

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1676 元
贡献
715 点

美女勋章热心勋章星光勋章新人勋章贡献勋章管理勋章帅哥勋章爱心勋章规矩勋章元老勋章水王勋章

沙发
发表于 2014-4-26 12:45:04 | 只看该作者
你的代码问题比较多。

1.主程序中,少两个 End Do
2.我在 IMSL 里找到的 NEQNF 是 7 个参数,而你给了 9 个。且第一个参数应该为一个外部函数,你给的是 Zr(i)

你先改这两个问题吧。


另外,我很好奇,这代码是你自己书写的吗?
为什么要用 common 呢?而且还用了 pointer
一个很新潮的指针,和一个老掉牙的 common 语句,放一起真是...很另类

17

帖子

5

主题

0

精华

入门

F 币
86 元
贡献
52 点
板凳
 楼主| 发表于 2014-4-26 21:03:56 | 只看该作者
fcode 发表于 2014-4-26 12:45
你的代码问题比较多。

1.主程序中,少两个 End Do

见笑了,我改改,那个啥我是模仿来的,嗯,谢谢你

40

帖子

8

主题

0

精华

熟手

F 币
91 元
贡献
105 点
地板
发表于 2014-6-20 20:48:09 | 只看该作者
fcode 发表于 2014-4-26 12:45
你的代码问题比较多。

1.主程序中,少两个 End Do

这是新手,我也是新学的,其中关于传递参数,指针有这个功能,common也有这个功能,但是common又有面临参数很多的问题,所以我们会几种方法混合用

2

帖子

0

主题

0

精华

新人

F 币
15 元
贡献
4 点
5#
发表于 2023-8-2 14:27:04 | 只看该作者
您好,请问您求解嵌套非线性方程组的问题解决了吗?
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2025-4-28 23:25

Powered by Discuz! X3.4

© 2013-2025 Comsenz Inc.

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