Message Boards Message Boards

0
|
3788 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

How can I automate parameter sensitivity?

Posted 11 years ago
Hi,

I am trying to automate computing parameter sensitivities to my model. The question I have is, in the code below, How can I replace the term [p, kb] in the derivative term with a list, so that when I Table through the list, I am computing the sensitivity to the next parameter. For example, the first list should read {p, kb} and the second {ka, p}. I've used ReplacePart thus far and called it pset, which I beleive is correct because I get a list that read ( {p, ka}, {ka,p})  however if I replace the term [p, kb] with pset[[1]], the code fails to compute the derivative. (shown below the working code example). Can someone tell me what I have done incorrectly?

Thank You for your help!
 sol = ParametricNDSolve[{
     A'[t] == -ka*A[t],
     B'[t] == ka*A[t] - kb*B[t],
     c'[t] == kb*B[t],
     A[0] == 10.0,
     B[0] == 0.0,
     c[0] == 0.0
     },
    {A, B, c},
   {t, 0.0, 300.0},
   {ka, kb}];
Species = {A, B, c};
Table[Species[[i]], {i, 1, 3}]
param = {ka, kb};

ka = 0.1;
kb = 0.2;
pset = Table[ReplacePart[param, i -> p], {i, 1, 2}]

Plot[Evaluate[(Species[[1]][0.1, 0.1][t] + {0, .25, -.25} D[Species[[1]][p, kb], p][t] /. p -> 1) /. sol], {t, 0, 30}, Filling -> {2 -> {3}}]
Plot[Evaluate[(Species[[1]][0.1, 0.1][t] + {0, .25, -.25} D[Species[[1]][pset[[1]]], p][t] /. p -> 1) /. sol], {t, 0, 30}, Filling -> {2 -> {3}}]

Patrick
POSTED BY: Pat Mac
Posted 11 years ago
Solved! Well sort of... It works for me. If anyone can think of a better solution, I'd be glad to hear it. In the mean time I'll post mine below.
 Clear["Global`*"]
 Species = {A, B, c};
 sol = ParametricNDSolve[{
     A'[t] == -ka*A[t],
     B'[t] == ka*A[t] - kb*B[t],
     c'[t] == kb*B[t],
     A[0] == 10.0,
     B[0] == 0.0,
     c[0] == 0.0},
   {A, B, c},
   {t, 0.0, 300.0},
   {ka, kb}
   ];
ka = 0.1;
kb = 0.1;
param = {ka, kb};
paramname = {"ka", "kb"};
pset = Table[ReplacePart[param, i -> p], {i, 1, 2}];
bound = {{0, .1, -.1}, {0, .5, -.5}, {0, -.5, .5}};
dfunc[pset_] := Table[
   Plot[
    Evaluate[(Species[[i]][0.1, 0.1][t] + bound[[i]]D[Species[[i]][pset[[j, 1]], pset[[j, 2]]], p][t] /. p -> 1) /. sol],
    {t, 0, 30},
    Filling -> {2 -> {3}},
    PlotLabel -> ToString[Species[[i]]] <> "  " <> ToString[paramname[[j]]],
    PlotRange -> All,
    ImageSize -> 350],
   {j, 1, 2},
   {i, 1, 3}];
GraphicsGrid[dfunc[pset]]
POSTED BY: Pat Mac
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract