小编Ger*_*ine的帖子

Fortran - 显式接口

我对Fortran很新,而且对于我的研究,我需要让一个模型运行的怪物,所以我正在学习,因为我正在进行.如果我问一个"愚蠢"的问题,我很抱歉.我正在尝试编译(Mac OSX,从命令行),我已经设法解决了一些问题,但现在我遇到了一些我不确定如何解决的问题.我想我得到了错误背后的想法,但同样,不知道如何解决.

模型很大,所以我只会发布我认为相关的代码部分(虽然我可能是错的).我有一个包含几个子程序的文件,它以:

    !==========================================================================================!
!    This subroutine simply updates the budget variables.                                  !
!------------------------------------------------------------------------------------------!
subroutine update_budget(csite,lsl,ipaa,ipaz)

   use ed_state_vars, only : sitetype     ! ! structure
   implicit none

   !----- Arguments -----------------------------------------------------------------------!
   type(sitetype)  , target     :: csite
   integer         , intent(in) :: lsl
   integer         , intent(in) :: ipaa
   integer         , intent(in) :: ipaz
   !----- Local variables. ----------------------------------------------------------------!
   integer                      :: ipa
   !----- External functions. -------------------------------------------------------------!
   real            , external   :: compute_water_storage
   real            , external   :: compute_energy_storage
   real            , external   :: compute_co2_storage
   !---------------------------------------------------------------------------------------!


   do ipa=ipaa,ipaz
      !------------------------------------------------------------------------------------!
      ! …
Run Code Online (Sandbox Code Playgroud)

fortran compilation explicit-interface

9
推荐指数
1
解决办法
1万
查看次数

NbClust包错误

我试图在我的数据(100行x 130列)上运行包NbClust来确定我应该选择的簇数,但是如果我尝试将它应用于完整数据集,我会不断收到此错误:

> nc <- NbClust(mydata, distance="euclidean", min.nc=2, max.nc=99, method="ward",
index="duda")     
[1] "There are only 100 nonmissing observations out of a possible 100 observations."
Error in NbClust(mydata, distance = "euclidean", min.nc = 2, max.nc = 99,  : 
The TSS matrix is indefinite. There must be too many missing values. The index cannot be calculated.
Run Code Online (Sandbox Code Playgroud)

当我将方法应用于100x80矩阵时,它确实产生了所需的输出(100x100也给了我一个错误信息,但是不同的一个).但是,显然,我想将此方法应用于整个数据集.仅供参考 - 创建距离矩阵,并使用Ward's Method进行聚类都没有问题.距离矩阵和树状图都是......

r cluster-analysis

7
推荐指数
2
解决办法
1万
查看次数

辛普森在Python中的规则

对于数值方法类,我需要编写一个程序来评估Simpson复合规则的定积分.我已经走到这一步了(见下文),但我的回答并不正确.我用f(x)= x测试程序,积分在0到1之间,结果应为0.5.我得到了0.78746 ...等我知道Scipy有一个Simpson规则,但我真的需要自己编写.

我怀疑这两个循环有问题.我之前试过"for i in range(1,n,2)"和"for i in range(2,n-1,2)",这给了我0.41668333的结果...等我也试过了x + = h",我试过"x + = i*h".第一个给了我0.3954,第二个选项给了我7.9218.

# Write a program to evaluate a definite integral using Simpson's rule with
# n subdivisions

from math import *
from pylab import *

def simpson(f, a, b, n):
    h=(b-a)/n
    k=0.0
    x=a
    for i in range(1,n/2):
        x += 2*h
        k += 4*f(x)
    for i in range(2,(n/2)-1):
        x += 2*h
        k += 2*f(x)
    return (h/3)*(f(a)+f(b)+k)

def function(x): return x

print simpson(function, 0.0, 1.0, 100)
Run Code Online (Sandbox Code Playgroud)

python math numerical-methods

5
推荐指数
1
解决办法
3万
查看次数