Fortran Coder

查看: 17662|回复: 4

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

[复制链接]

17

帖子

5

主题

0

精华

入门

F 币
86 元
贡献
52 点
发表于 2014-4-26 12:15:59 | 显示全部楼层 |阅读模式
我要求A1,A3,可是只有含有A1,A3的表达式A,B,C,D的关系式,编程如下,求大师指导
[Fortran] 纯文本查看 复制代码
program tu2
use IMSL
implicit none
external FCN
real*8 FCN
real,parameter::ERRREL=0.0001
integer,parameter::N=2
integer,parameter::ITMAX=100
real*8::XGUESS(N)=(/0.0467,0.0732/)
real X(N),FNORM
real*8 A1,A2,A3,A,B,C,D
real*8 Z0,Zi
real*8 E,F
real,parameter::pi=3.14159
integer,parameter::Zrs=5
integer,parameter::A4s=9
integer k,i
real*8::Zr(Zrs)=(/1.0,2.0,3.0,4.0,5.0/)
real*8::A4(A4s)=(/0.075,0.10,0.15,0.20,0.25,0.30,0.35,0.40,0.425/)
common /group2/ zi
common /group3/ A2
!!**************************************************
Zi=-3.0                  !!天线阻抗虚部的值
Z0=50.0                  !!传输线的特性阻抗
A2=0.25                  !!第二个支节的长度
!!***************************************************
do i=1,Zrs
do k=1,A4s
call  NEQNF(Zr(i),A4(k),FCN(i,k),ERRREL,N,ITMAX,XGUESS,X,FNORM)
write(*,*) X
stop
end
!!!**************************
subroutine A4_get_A(A4,A)
implicit none
real*8 A2,A3,A4,A
real,parameter::pi=3.14159
common /group3/ A2
A=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的函数式

return
end
!!!***************************
subroutine A4_get_B(A4,B)
implicit none
real*8 A2,A3,A4,z0,B
real,parameter::pi=3.14159
common /group3/ A2
common /group1/ Z0
B=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的函数式
return
end
!!*****************************
subroutine A4_get_C(A4,C)
implicit none
real*8 A1,A2,A3,A4,Z0,C
real,parameter::pi=3.14159
common /group3/ A2
common /group1/ Z0
C=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)))
return
end
!!*******************************
subroutine A4_get_D(A4,D)
implicit none
real*8 A1,A2,A3,A4,D
real,parameter::pi=3.14159

common /group3/ A2
D=-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))
return
end
!!****************************************************

subroutine FCN(A,B,C,D,A4,Zr,XA,F,N)
implicit none
integer N
real,target::XA(N)
real F(N)
real,pointer::A1,A3
real*8 A,B,C,D,A4,Z0,Zr,Zi
common /group1/Z0
common /group2/Zi

A1=>XA(1)
A3=>XA(2)
call A4_get_A(A4,A)
call A4_get_B(A4,B)
call A4_get_C(A4,C)
call A4_get_D(A4,D)

F(1)=A*D+B*C-Z0*((D-C*Zi)*(D-C*Zi)+(C*Zr)*(C*Zr))
F(2)=(D*A-B*C)*Zi-A*C*(Zr*Zr+Zi*Zi)+D*B
return
end

以下是错误指示
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)

在此谢过!!

1947

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1295 元
贡献
545 点

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

发表于 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 点
发表于 2023-8-2 14:27:04 | 显示全部楼层
您好,请问您求解嵌套非线性方程组的问题解决了吗?
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-3-28 19:46

Powered by Tencent X3.4

© 2013-2024 Tencent

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