2
$\begingroup$

I have the following equations and settings:

Clear[koff]; koff = 5.*10^-5;
Clear[kon]; kon = 1.*10^4;
Clear[koff2]; koff2 = 1.*10^-5;
Clear[kon2]; kon2 = 1.*10^4;
Clear[kcg]; kcg = 1.2*10^-5;
Clear[ndsolKRH];
ndsolKRH =
  NDSolve[{
      D[ag[t], t] == -kon2*ag[t]*b[t] + koff2*cg[t] - kcg ag[t], 
      D[a[t], t] == -kon*a[t]*b[t] + koff*c[t], 
      D[cg[t], t] == kon2*ag[t]*b[t] - koff2*cg[t], 
      D[c[t], t] == kon*a[t]*b[t] - koff*c[t], 
      D[b[t], t] == -kon2*ag[t]*b[t] - kon*a[t]*b[t] + koff2*cg[t] + koff*c[t],
      ag[0] == 450. 10^-9, a[0] == 90.247 10^-9, cg[0] == 0, 
      c[0] == 473.75 10^-9, b[0] == 26.25 10^-9},
    {ag, a, b, c, cg},
    {t, 0, 1200000}][[1]];

I would like to get a table of individual numbers for cg and ag. I would also lime to be able to plot these variables vs time. At present I can do it one at a time but there must be a lot easier way.

I am doing the following:

Clear[solKRHfix]; solKRHfix = ag /. ndsolKRH;

AND THEN:

solKRHfix[600000]
$\endgroup$
  • 2
    $\begingroup$ Fixed formatting, but didn't spend any time working out what the unrecognized symbols are. Please check my edit and modify as needed. $\endgroup$ – bobthechemist Aug 2 '14 at 16:32
3
$\begingroup$

Assuming that I interpreted the input correctly,

koff = 5. 10^-5;
kon = 1. 10^4;
koff2 = 1. 10^-5;
kon2 = 1. 10^4;
kcg = 1.2 10^-5;

ndsolKRH = NDSolve[{
     ag'[t] == -kon2*ag[t]*b[t] + koff2*cg[t] - kcg ag[t],
     a'[t] == -kon*a[t]*b[t] + koff*c[t],
     cg'[t] == kon2*ag[t]*b[t] - koff2*cg[t],
     c'[t] == kon*a[t]*b[t] - koff*c[t],
     b'[t] == -kon2*ag[t]*b[t] - kon*a[t]*b[t] + koff2*cg[t] + koff*c[t],
     ag[0] == 450. 10^-9,
     a[0] == 90.247 10^-9,
     cg[0] == 0,
     c[0] == 473.75 10^-9,
     b[0] == 26.25 10^-9},
    {ag, a, b, c, cg},
    {t, 0, 200000}][[1]];

Plot[(# /. ndsolKRH)[t], {t, 0, 200000},
    Frame -> True,
    Axes -> False,
    FrameLabel -> {t, ToString[#] <> "[t]"},
    ImageSize -> 300] & /@
  {ag, a, b, c, cg} // Column

enter image description here

EDITED: Added Table.

TableForm[
 Table[(func /. ndsolKRH)[t],
  {t, 0, 200000, 20000},
  {func, {ag, a, b, c, cg}}],
 TableHeadings -> {
   Range[0, 200000, 20000],
   (ToString[#] <> "[t]") & /@ {ag, a, b, c, cg}}]

enter image description here

$\endgroup$
2
$\begingroup$
Clear[koff]; koff = 5.*10^-5;
Clear[kon]; kon = 1.*10^4;
Clear[koff2]; koff2 = 1.*10^-5;
Clear[kon2]; kon2 = 1.*10^4;
Clear[kcg]; kcg = 1.2*10^-5;
Clear[ndsolKRH];
ndsolKRH =
  NDSolve[{
      D[ag[t], t] == -kon2*ag[t]*b[t] + koff2*cg[t] - kcg ag[t], 
      D[a[t], t] == -kon*a[t]*b[t] + koff*c[t], 
      D[cg[t], t] == kon2*ag[t]*b[t] - koff2*cg[t], 
      D[c[t], t] == kon*a[t]*b[t] - koff*c[t], 
      D[b[t], t] == -kon2*ag[t]*b[t] - kon*a[t]*b[t] + koff2*cg[t] + koff*c[t],
      ag[0] == 450. 10^-9, a[0] == 90.247 10^-9, cg[0] == 0, 
      c[0] == 473.75 10^-9, b[0] == 26.25 10^-9},
    {ag, a, b, c, cg},
    {t, 0, 1200000}][[1]];

{ag, a, b, c, cg} = ndsolKRH[[All, 2]];

tbl = Table[Through[{ag, a, b, c, cg}[t]], {t, 0, 1200000, 100000}];
heading = 
  Replace[Hold[{ag, a, b, c, cg}], s_ :> ToString[Unevaluated[s]], {2}] // ReleaseHold;
TableForm[tbl, TableHeadings -> {Range[0, 1200000, 100000], heading}]

table

Plot[Evaluate@Through[{ag, a, b, c, cg}[t]], {t, 0, 1200000}]

plot

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.