Message Boards Message Boards

Telling NDSolve to solve for reals only

Clear["Global'*"];
    Table[khi = 74; ro2 = 3400; kmrs = 8; kisu = 0; kmp = .05; kros = .05;
      kres = 8.333;
     kccc1 = 19; k23 = 17; kvp = 0.04; kc = 21; nc = 5; km = 80; nm = 4.5;
     km2 = 350; nm2 = 4.5; kv1 = 17; nv1 = 6; kv2 = 1200; nv2 = 6; 
     kvs = 100; nvs = 9; 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)) (1 - 1/((fs[t]/kvs)^nvs + 1)))/(
       volc (c[t] + kmccc1) ((f3[t]/kv2)^nv2 + 1)) + (
       nut vhi)/((kmhi + nut) ((c[t]/kc)^nc + 1) ((fs[t]/kfc)^nfc + 
          1) ) - (vmrs volm c[t])/(
       volc (c[t] + kmmrs) ((c[t]/km)^nm + 1) ((fs[t]/km2)^nm2 + 1));
     oderos = kmp fm[t] o2[t] - kros ros[t] fs[t] - a ros[t];
     odefm = -(a fm[t]) + (
       vmrs c[t])/((c[t] + kmmrs) ((c[t]/km)^nm + 1) ((fs[t]/km2)^nm2 + 
          1)) - kisu fm[t] - kmp fm[t] o2[t];
     odefs = kisu fm[t] - kros ros[t] fs[t] - a fs[t];
     odemp = kmp fm[t] o2[t] + kros ros[t] fs[t] - a mp[t];
     odeo2 = -(kmp fm[t] o2[t]) - kres fs[t] o2[t] + 
       ro2/((o2[t]/270)^9 + 1);
     odef2 = -(a f2[t]) - k23 f2[t] (1 - 1/((c[t]/k32)^n32 + 1)) + (
       vkccc1 c[
         t] (1 - 1/((c[t]/kv1)^nv1 + 1)) (1 - 
          1/((fs[t]/kvs)^nvs + 1)))/((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], vp[t], fm[t], fs[t], mp[t], o2[t], 
       ros[t]};
     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, 
        ros'[t] == oderos, c[0] == 30, f2[0] == 100, f3[0] == 100, 
        fm[0] == 50, fs[0] == 50, mp[0] == 0, o2[0] == 100, vp[0] == 100, 
        ros[0] == 0}, vars, {t, 0, 31}];
     vars;
     vars /. solution /. 
      t -> 31, {nut, {4, 7, 16, 26, 46, 106, 1006, 10006}}] 

Using this code above I keep getting imaginary solutions, which I don't want. I tried looking in the documentation for a solution but I couldn't see it. I very possibly could've missed it. Any assistance is appreciated.

POSTED BY: Josh Wofford

Using this code above I keep getting imaginary solutions, which I don't want.

Well, if that is the solution, then there is really nothing you can do about it. You can always change the problem to obtain a solution that does not generate a complex solution.

But if you want to remove the complex terms after you obtain the solution, then you can try something as

myImaginarySolution = x^3 + 2 Sin[x t] + 3 I + t Sin[2 t] - 5 I x;
Simplify @ ComplexExpand @  Re @ myImaginarySolution

   x^3 + t Sin[2 t] + 2 Sin[t x]

btw, DSolve does not take assumptions. (but I think functions, if any, called by DSolve uses assumptions, I seem to remember this). So if you try to make assumptions before calling DSolve (as in Assuming[....,DSolve]), these will be ignored by DSolve. Which removes terms that are complex, returning

POSTED BY: Nasser M. Abbasi
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