Ask Your Question
0

How to write a differential equation with two enumeration

asked 2024-02-23 16:10:44 +0100

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.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2024-02-24 00:30:50 +0100

Max Alekseyev gravatar image

updated 2024-02-24 00:32:08 +0100

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.

edit flag offensive delete link more

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: 2024-02-23 16:10:44 +0100

Seen: 166 times

Last updated: Feb 24