defining ODEs recursively in maple

62 Views Asked by At

I want to numerically look at a system of ODEs with a large number of variables; defined by $da_j(t)/dt= 2^j a_{j-1}^2 - 2^{j+1} a_j a_{j+1}$, for $j=0\ldots50$ with $a_{-1}= a_{51}=0$.

In maple, I wrote down

ODEs := 
diff(a0(t), t) = -2*a0(t)*a1(t), 
diff(a1(t), t) = 2*a0(t)*a0(t)-2^2*a1(t)*a2(t), 
diff(a2(t), t) = 2^2*a1(t)*a1(t)-2^3*a2(t)*a3(t), 
diff(a3(t), t) = 2^3*a2(t)*a2(t)-2^4*a3(t)*a4(t), 
diff(a4(t), t) = 2^4*a3(t)*a3(t)-2^5*a4(t)*a5(t), 
diff(a5(t), t) = 2^5*a4(t)*a4(t)-2^6*a5(t)*a6(t), 
diff(a6(t), t) = 2^6*a5(t)*a5(t)-2^7*a6(t)*a7(t), 
diff(a7(t), t) = 2^7*a6(t)*a6(t)-2^8*a7(t)*a8(t), 
diff(a8(t), t) = 2^8*a7(t)*a7(t)-2^9*a8(t)*a9(t), 
diff(a9(t), t) = 2^9*a8(t)*a8(t)-2^10*a9(t)*0

ICs := 
a0(0) = 1, a1(0) = 0, a2(0) = 0, a3(0) = 0, 
a4(0) = 0, a5(0) = 0, a6(0) = 0, a7(0) = 0, 
a8(0) = 0, a9(0) = 0

but I am certainly getting tired of writing down the equation for each $j$ individually. Does Maple have a method to define the ODE for all of $a_j(t)$ simultaneously?

In addition, is there a way to improve the accuracy when it numerically solves a system of ODEs? I wouldn't mind waiting for a long time.

1

There are 1 best solutions below

0
On BEST ANSWER

Apart from the use of loops and other programming construct mentioned in the comments, there is one easy thing to do to tame the equations a little: Replace the functions by $b_j(t)=2^j⋅a_j(t)$. Then $$ \dot b_j=2^j⋅\dot a_j(t) =2^{2j}⋅a_{j−1}(t)^2−2^{2j+1}⋅a_j(t)⋅a_{j+1}(t) =4⋅b_{j−1}(t)^2-b_j(t)⋅b_{j+1}(t) $$ has much smaller constants, increasing the chances for numerical accuracy. Still, the function values might be large, contributing to a large local Lipschitz constant.