使用 DifferentialEquations.jl Julia 包时的方法错误

Method error when using DifferentialEquations.jl Julia package

我正在尝试使用 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})并且错误发生在以下行中solve() 函数是。

事先感谢您的帮助!

未经检验的预感:变化:

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

至:

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

前者会创建一个一列的二维矩阵。后者将创建一个一维向量。您看到的错误消息是它在需要一维数组的地方得到了一个二维数组。