Ask Your Question
0

How to write a differential equation with two enumeration

asked 1 year ago

anonymous user

Anonymous

How to write a differential equation with two enumeration like this P'_i,j (t) = beta * (i+1) * (j-1) * P_i+1,j-1 (t) - (beta * i * j + gamma * j) * P_i,j (t) + gamma * (j+1) * P_i,j+1 (t) in Sage Math. This is a stochastic SIR epidemic model where P_i,j (t) is the probability there are i susceptible, j infected and N-(i+j) recovered individuals at time t with 0<=i+j<=N.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 1 year ago

Max Alekseyev gravatar image

updated 1 year ago

I'm not sure what you mean under "write", but if you question is about defining 2D array of functions P, you can proceed like this:

N = 4
t = var('t')
P =  Matrix(N+1,N+1, lambda i,j: function(f'P_{i}_{j}')(t) if i+j<=N else 0)
print(P)

which gives

[P_0_0(t) P_0_1(t) P_0_2(t) P_0_3(t) P_0_4(t)]
[P_1_0(t) P_1_1(t) P_1_2(t) P_1_3(t)        0]
[P_2_0(t) P_2_1(t) P_2_2(t)        0        0]
[P_3_0(t) P_3_1(t)        0        0        0]
[P_4_0(t)        0        0        0        0]

Then you can work with functions P[i,j] as you like, including defining differential equations over them.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 1 year ago

Seen: 193 times

Last updated: Feb 24 '24