本文介绍了建筑阵列中的增量小于1 - 的Fortran的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立在增量步骤的数组。我猜必须有类似于Matlab的载体建设,例如功能矢量(1:0.1:2),它建立了一个载体,用在0.1的步骤从1值2填充。有没有办法在FORTRAN做到这一点?

I'm trying to build an array in incremental steps. I'm guessing there must be a function analogous to matlab's vector building, e.g. vector(1:0.1:2) which builds a vector and fills it with values from 1 to 2 in 0.1 steps. Is there a way to do this in fortran?

推荐答案

您可以使用数组构造函数显示在以下code:

You can use the array constructor as shown in the following code:

program main
  implicit none
  real,allocatable,dimension(:) :: vec
  real                          :: a,inc
  integer                       :: n ,i
  a = 1.    ! initial value
  inc = 0.1 ! increment value
  n = 11    ! number of values  
  allocate(vec(n))
  vec = [(a + (i-1) * inc, i=1,n)]  ! array constructor
  write(*,'(11f7.2)') vec
end program main

出:

1.00   1.10   1.20   1.30   1.40   1.50   1.60   1.70   1.80   1.90   2.00

这篇关于建筑阵列中的增量小于1 - 的Fortran的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 12:04