How does one have multiple random variables in an SDEProblem?

I’m trying to simulate a stochastic state space model which looks something like:

x_dot(x) = A*x + B*u(x + n) + d

A and B are matrices, x, n, and d are vectors and u is an affine function.
Each of the elements of n and d are independent random variables.
How can I implement this as an SDEProblem for DifferentialEquations.jl?

I’ve figured out how to do this for d but only for the special case where d=v*W where v is a vector and W is a scalar random variable.

r = 1
kp = 0.5
kr = 0.5
A = [0 1
	 0 0]
B = [0,1]
u(x) = -kp*x[1] - kr*r
f(x,p,t) = A*x + B*u(x)
v = 0.3*[kp,1]
g(u,p,t) = v

prob = SDEProblem(f,g,[0,0], (0,10))
plot(solve(prob))

The documentation for SDE problem mentions that g can be a vector such that the equation becomes:


But I’ve tried giving g as both a vector of vectors and a matrix and it always gives an error. What does g need to look like to have multiple independent random variables?

See this tutorial:

1 Like

Thank you!
So what I was missing was the kwarg noise_rate_prototype which is an argument which is of the same type as the output of g.

r = 1
kp = 0.5
kr = 0.5
A = [0 1
	 0 0]
B = [0,1]
u(x) = -kp*x[1] - kr*r
f(x,p,t) = A*x + B*u(x)
g(u,p,t) = 0.1*[[kp,1] [kp,0.5]]

prob = SDEProblem(f,g,[0,0], (0,10), noise_rate_prototype = zeros(2, 2))
plot(solve(prob))