Fortran语言功能说明 [英] Fortran Function explanation

查看:215
本文介绍了Fortran语言功能说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Fortran语言这个功能,我试图重新编码在C#



 Ç****** ************************************************** ******** 
C功能POLY
C ****************************** ***********
功能POLY(N,A,X)
尺寸A(N)
C
POLY = 0
L = N
执行1 K = 1,N
POLY = POLY * X + A( L)
1 L = L-1
返回

C *********************** ******************************************

我发现尺寸A(N)创建<$ C的矢量$ C> N 值,但我们已经有了一个变量 A 从函数的参数,这是否意味着数组值都等于 A ?如果是这样的话有什么用 A(N)的
顺便问一下谁能只是解释一下,这种功能就这样我就可以在C#中重新实现


解决方案

 函数POLY(N,A,X)!隐实(浮点)函数聚(INT N,int类型的,真正的X)
尺寸A(N)!塑造n个值的一维数组在此范围内
C!甭(空白评论)
POLY = 0!初始化返回变量浮动值0
L = N!集L(隐式整数)N
执行1 K = 1,N!对于(INT K = 1; K< = N; ++ K),
POLY = POLY * X + A(L)!更新返回变量
1分配L = L-1! L减
的回报!返回聚

电流值



所以在C的语法:



 浮聚(INT N,int类型的,浮动X){
// REDIM A(N)
float结果= 0;
INT L = N;
为(INT K = 1; K< = N; ++ K){
结果=结果* X + A(L);
--L;
}
返回结果;
}

这不翻译位redimensioning A作为一个数组。在C语言中,你会传递一个指针,并把它作为一个数组,并在C ++ / C#你可能会通过用自己的length属性矢量状结构。



在C#中使用列表:

 浮聚(名单<浮动> coeffs,浮X){
float结果= 0;
的for(int i = coeffs.Count-1; I> = 0; --i){
结果=结果* X + COEFF [I]
}
返回结果;
}


I have this function in Fortran and i'm trying to recode it in C#

C **************************************************************** 
C    FUNCTION   POLY 
C***************************************************************** 
      FUNCTION POLY(N,A,X) 
      DIMENSION A(N) 
C
      POLY    = 0. 
      L       = N 
      DO 1 K  = 1,N 
      POLY    = POLY*X + A(L) 
1     L       = L-1 
      RETURN 
      END 
C***************************************************************** 

I found out that DIMENSION A(N) creates a vector of N values, but we already have a variable A from the function parameters, does this means that the array values all equal to A? If so then what is the use of A(N). By the way can anyone just explain what does this function do so i can re-implement it in C#

解决方案

      FUNCTION POLY(N,A,X)      ! implicitly real (float) function poly(int n,int a,real x)
      DIMENSION A(N)            ! shape A as 1d array of n values in this scope
C                               ! say nothing (blank comment)
      POLY    = 0.              ! initialise return variable to float value 0
      L       = N               ! set L (implicitly integer) to n
      DO 1 K  = 1,N             ! for(int k=1; k<=n; ++k)
      POLY    = POLY*X + A(L)   !    update return variable
1     L       = L-1             !    decrement L
      RETURN                    ! return current value for poly
      END 

so in c-like syntax:

float poly(int n, int a, float x) {
    // redim a(n)
    float result = 0;
    int l = n;
    for(int k=1; k <= n; ++k) {
        result = result*x + a(l);
        --l;
    }
    return result;
}

The bit that doesn't translate is redimensioning A as an array. In C you would pass a pointer and use it as an array, and in C++/C# you'd probably pass a vector-like structure with its own length property.

In C#, using a list:

float poly(List<float> coeffs, float x) {
    float result = 0;
    for(int i=coeffs.Count-1; i >= 0; --i) {
        result = result*x + coeff[i];
    }
    return result;
}

这篇关于Fortran语言功能说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆