error-handling - 使用DifferentialEquations.jl Julia程序包时的方法错误

标签 error-handling type-conversion julia differential-equations differentialequations.jl

我正在尝试使用DifferentialEquation.jl包解决ode45微分方程,但出现方法错误。

using DifferentialEquations

M = 400; m = 35;
C = 3e3; c = 300;
K = 50e3; k = 200e3;
A = 0.05; L = 0.5; vh = 13.9

MM = [M 0;
      0 m] # mass matrix

CC = [C -C;
     -C C+c] # damping matrix

KK = [K -K;
     -K K+k] # stiffness matrix

w(t) = A*sin(2*pi*vh*t/L)
wd(t) = A*2*pi*vh*t/L*cos(2*pi*vh*t/L) # dw/dt

n = 2 # number of (original) equations
Mi = MM^(-1)
AA = [zeros(n,n) eye(n); -Mi*KK -Mi*CC]

f(t) = [0; c*wd(t)+k*w(t)] # force vector
g(t,y) = AA*y+[zeros(n,1); Mi*f(t)]

y0 = zeros(4) # initial conditions
tspan = (0.0, 0.5) # time span

prob = ODEProblem(g, y0, tspan) # defining the problem
solve(prob) 

该代码给出一个错误,指出:

MethodError: Cannot convert an object of type Array{Float64,2} to an object of type Array{Float64,1} This may have arisen from a call to the constructor Array{Float64,1}(...), since type constructors fall back to convert methods.



尽管我相信错误可能与y0有关(因为typeof(y0)= Array {Float64,1}),并且错误发生在resolve()函数所在的行中,但我没有得到可能做错的事情是。

预先感谢您的帮助!

最佳答案

未经测试的预感:更改:

g(t,y) = AA*y+[zeros(n,1); Mi*f(t)]

至:
g(t,y) = AA*y+[zeros(n); Mi*f(t)]

前者将创建一列的二维矩阵。后者将创建一维 vector 。您看到的错误消息是它在期望一维数组的地方得到了二维数组。

关于error-handling - 使用DifferentialEquations.jl Julia程序包时的方法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46206060/

相关文章:

laravel - Laravel错误未传递给 View

php - 为什么我不能用 PHP 5.2 处理 CakePHP 2.x 中的 fatal error ?

c++ - 将字符串转换为 char 和 int 数据类型

ruby-on-rails - rails : Why does update_attribute automatically convert types

C#类型转换: Explicit cast exists but throws a conversion error?

arrays - 如何将数组数组转换为矩阵?

python - 字符串索引在python中为什么必须是整数?

asp.net - 如何捕获在我的 ASCX 控件(而不是代码隐藏)上引发的异常?

string - 如何将整数转换为没有 0x 的十六进制字符串(Julia 1.0)

linux - 我可以在不创建新环境的情况下在 anaconda 上安装 julia 吗?