I'm trying to solve an ode45 differential equation with the DifferentialEquation.jl package but I'm getting a method error.
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)
The code gives an error that says:
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.
I do not get what I might be doing wrong, although i believe the error might have something to do with y0 (since typeof(y0) = Array{Float64,1}) and the error occures in the line where the solve() function is.
Thanks for any help beforehand!
Untested hunch: change:
to:
The former will create a two-dimensional matrix with one column. The latter will create a one-dimensional vector. The error message you're seeing is that it's getting a two dimensional array in a place where it expects a one-dimensional one.