0
|
5159 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
GROUPS:

# Can anyone explain why my code isn't working?

Posted 9 years ago
 So I've got this question: Two genes A and B each switch off the other. Their activity also decays with time, but at different rates. The change in A and B expression with time can be described using the following 2 ordinary differential equations. dA/dt= 0.5/(1+(B/Subscript[K, 1])^n)-0.2A dB/dt= 1/(1+(A/Subscript[K, 2])^n)-2B  Use Mathematica to numerically solve the above system of ordinary differential equations for t=0 to t=120 minutes. Plot your solution on a single plot. Assume: Initial condition: At t=0, A=0nmol/m^3 and B=0nmol/(m^3). Subscript[K, 1]=0.5nmol/m^3 Subscript[K, 2]=2nmol/m^3 n=10 And I'm trying to solve the problem. I've got this so far: N[DSolve[{A'[t] == 0.5/((1 + (B[t]/.5))^10) - 0.2 A[t], B'[t] == 0.5/(1 + (A[t]/2))^10 - 2 B[t], A == 0, B == 0}, {A[t], B[t]}, {t, 0, 120}]]  And all it's doing is returning: {{A[t] -> InterpolatingFunction[{{0., 120.}}, <>][t], B[t] -> InterpolatingFunction[{{0., 120.}}, <>][t]}}  And Mathematica says it's still running and has been for about 7 or 8 minutes now. Can anyone explain where I've gone wrong or how I can solve this problem correctly? Thanks
2 Replies
Sort By:
Posted 9 years ago
 You tried to find analytical solution the turning it to numbers N[DSolve... better above or: In:= sol = NDSolve[{A'[t] == 0.5/((1 + (B[t]/.5))^10) - 0.2 A[t], B'[t] == 0.5/(1 + (A[t]/2))^10 - 2 B[t], A == 0, B == 0}, {A[t], B[t]}, {t, 0, 120}] Out= {{A[t] -> InterpolatingFunction[{{0., 120.}}, <>][t], B[t] -> InterpolatingFunction[{{0., 120.}}, <>][t]}} In:= Plot[{A[t], B[t]} /. sol, {t, 0, 120}] Posted 9 years ago
 Best is to use the function NDSolveValue. For example as follows: {Asol, Bsol} = NDSolveValue[{A'[t] == 0.5/((1 + (B[t]/.5))^10) - 0.2 A[t], B'[t] == 0.5/(1 + (A[t]/2))^10 - 2 B[t], A == 0, B == 0}, {A, B}, {t, 0, 120}] Plot[{Asol[t], Bsol[t]}, {t, 0, 120}] and get: 