Message Boards Message Boards

0
|
7880 Views
|
5 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Problem with calculations

Having a problem with a loop I am running. The second row, last column value should be .130004, not the 10^11 value that I get. Any ideas on what is going on? Copied and pasted the body of code, but not the result table.

Clear["Global'*"];
errortablewt = 
 Table[khi = 64; ro2 = 3400; kmrs = 4; kisu = 1.5; kmp = 0.5; 
  kres = 25;
  kccc1 = 76; k23 = 16; kvp = 0.04; kc = 21; nc = 5;
  km2 = 350; nm2 = 6; kv1 = 17; nv1 = 6; kv2 = 700; nv2 = 6; k32 = 18;
   n32 = 9; volc = .65; volm = 0.1; volv = 0.25; vhi = 2 khi nut;
  kmhi = 2; kfc = 200; nfc = 5; kmmrs = 5; vmrs = 2 kmrs c[t]; 
  vkccc1 = 2 kccc1 c[t]; kmccc1 = 20; a = 0.5;
  odec = -(a c[t]) - (vkccc1 volv c[t] (1 - 1/((c[t]/kv1)^nv1 + 1)))/(
    volc (c[t] + kmccc1) ((f3[t]/kv2)^nv2 + 1)) + (nut vhi)/(
    volc (kmhi + nut) ((c[t]/kc)^nc + 1) ((fs[t]/kfc)^nfc + 1)) - (
    vmrs volm c[t])/(volc (c[t] + kmmrs) ((fs[t]/km2)^nm2 + 1));
  odefm = -(a fm[t]) + (vmrs volc c[t])/(
    volm (c[t] + kmmrs) ((fs[t]/km2)^nm2 + 1)) - kisu fm[t] - 
    kmp fm[t] o2[t];
  odefs = kisu fm[t] - a fs[t];
  odemp = kmp fm[t] o2[t] - a mp[t];
  odeo2 = -(kmp fm[t] o2[t]) - kres fs[t] o2[t] + 
    ro2/((o2[t]/245)^9 + 1);
  odef2 = -(a f2[t]) - k23 f2[t] (1 - 1/((c[t]/k32)^n32 + 1)) + (
    vkccc1 volc c[t] (1 - 1/((c[t]/kv1)^nv1 + 1)))/(
    volv (c[t] + kmccc1) ((f3[t]/kv2)^nv2 + 1));
  odef3 = -(a f3[t]) + k23 f2[t] (1 - 1/((c[t]/k32)^n32 + 1)) - 
    kvp f3[t];
  odevp = kvp f3[t] - a vp[t];
  vars = {nut, c[t], f2[t], f3[t], fm[t], fs[t], mp[t], o2[t], vp[t], 
    rmsd};
  solution = 
   NDSolve[{Derivative[1][c][t] == odec, 
     Derivative[1][f2][t] == odef2, Derivative[1][f3][t] == odef3, 
     Derivative[1][fm][t] == odefm, Derivative[1][fs][t] == odefs, 
     Derivative[1][mp][t] == odemp, Derivative[1][o2][t] == odeo2, 
     Derivative[1][vp][t] == odevp, c[0] == 30, f2[0] == 100, 
     f3[0] == 100, fm[0] == 50, fs[0] == 50, mp[0] == 0, o2[0] == 100,
      vp[0] == 100}, vars, {t, 0, 31}];
  vars;
  vars1 = vars /. solution /. t -> 31;
  vars2 = Flatten[vars1];
  If[nut == 4, {feisomito = 480, fef3 = 0.0001, fefm = 33.6, 
    fefs = 334.2, femp = 48}, {"nut not 4"}];
  If[nut == 16, {feisomito = 544, fef3 = 1000, fefm = 152.32, 
    fefs = 107.09, femp = 310.08}, {"nut not 16"}];
  If[nut == 46, {feisomito = 770, fef3 = 1180, fefm = 154, fefs = 213,
     femp = 254.1}, {"nut not 46"}];
  If[nut == 106, {feisomito = 710, fef3 = 1400, fefm = 170.4, 
    fefs = 215.8, femp = 191.7}, {"nut not 106"}];
  rmsd = (1/
      4 (((vars2[[4]] - fef3)/fef3)^2 + ((vars2[[5]] - fefm)/
          feisomito)^2 + ((vars2[[6]] - fefs)/
          feisomito)^2 + ((vars2[[7]] - femp)/feisomito)^2));
  vars2, {nut, {4, 16, 46, 106}}]
POSTED BY: Josh Wofford
5 Replies

An alternative would be to clear rmsd first, on every pass. A shortcut for Clear is Set to dot like this =.

Table[rmsd =.; khi = 64; ro2 = 3400; kmrs = 4; kisu = 1.5; kmp = 0.5;

Oh I didn't realize that. Your first solution is working rather well, but I will jot this down as well if I want to shorten the code a little bit down the road. To answer the rmsd being a legitimate value of NDSolve, it's not a variable like the other 8 equations. It's something I've written to compare these values to physical values I am getting from experiments.

POSTED BY: Josh Wofford

Thanks a lot.

POSTED BY: Josh Wofford

Replacing

vars = {nut, c[t], f2[t], f3[t], fm[t], fs[t], mp[t], o2[t], vp[t], rmsd};

with

vars = {nut, c[t], f2[t], f3[t], fm[t], fs[t], mp[t], o2[t], vp[t]};

and later

Join[vars2, {rmsd}]

instead, will help.

Once rmsd is included in vars as a symbol the first time, then the symbol no longer exists after it is set to a value, for the next pass as it gets replaced by the evaluator. Is rmsd really a legitimate variable of the NDSolve equations?

After working through the math by hand I have noticed that mathematica is performing the calculations correctly, but the last column values are getting mixed around somehow. They are being shifted down a row and the bottom row is winding up on top for the last column only. I still would like some advice with this shuffling around of values if you have encountered this before.

POSTED BY: Josh Wofford
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