4
$\begingroup$

I have the following code below, that relates Concentration C[x,t], Time [t] and Space [x]:

Deff = 7.776*10^-2;(* Effective Diffusivity of Oxygen [cm^2/h] *)
dens = 2*10^6;(* Amount of cells in the cartilage pellet [cell] *)
qmax = 1*10^-8;(* Maximum Specific Consumption of Oxygen [mmol/cell] *)
ks = 1075*10^-2;(* Consumption Constant [mmol/L] *)
V = 3*10^-2; (* Cartilage Pellet Volume [L] *)
Ci = 10; (* Initial Oxygen Concentration when t\[Equal]0 [mmol/L] *)
Cs = 8.5; (*Superficial Oxygen Concentrationat x\[Equal]0 [mmol/L] *)

Manipulate[

 sol = First@
   NDSolve[{D[C[x, t], t] == 
      Deff*D[C[x, t], x, x] - (((dens*qmax)/V)*(C[x, t]/(ks + C[x, t]))), 
 C[x, 0] == Ci, C[0, t] == Cs + (Ci - Cs) Exp[-t/5], 
 Derivative[1, 0][C][10, t] == 0}, C[x, t], {x, 0, 10}, {t, 0, 48}, MaxStepSize -> 0.1];
 Plot3D[Evaluate[C[x, t] /. sol], {x, 0, 10}, {t, 0, 48}, ColorFunction -> "Rainbow"],
 {{Deff, 7.776*10^-2}, 7.776*10^-8, 7.776, Appearance -> "Labeled"},
 {{dens, 0}, 0, 2*10^6, Appearance -> "Labeled"},
 {{qmax, 1*10^-8}, 0, 1*10^2, Appearance -> "Labeled"},
 {{ks, 1075*10^-2}, 0, 1075*10^2, Appearance -> "Labeled"},
 {{V, 3*10^-2}, 3*10^-6, 30, Appearance -> "Labeled"},
 {{Ci, 10}, 0, 50, Appearance -> "Labeled"},
 {{Cs, 8.5}, 0, 50, Appearance -> "Labeled"}
          ]

This code is producing a surface graph. However, now I'm trying to plot 2D graphs from this surface (Concentration versus space and Concentration versus time) but I can't get it done. I intend to use the manipulate function for the time variable) on the Concentration versus Space graph, to analise the behaviour of the curve through time.

Is it possible? Could you please help me?

Any suggestions are very appreciated.

$\endgroup$

1 Answer 1

6
$\begingroup$

You can add two new graphs:

Plot[Evaluate[C[x1, t1] /. (sol  /. {x -> x1, t -> t1}) ], {x1, 0, 10}],
Plot[Evaluate[C[x2, t2] /. (sol  /. {x -> x2, t -> t2}) ], {t2, 0, 48}]

Here I added replacement rules to not cause interference with your function definitions.

I also added two new controls:

{{x2, 0}, 0, 10, Appearance -> "Labeled"},
{{t1, 0}, 0, 48, Appearance -> "Labeled"}

Full Code:

Manipulate[
 sol = First@
 NDSolve[{D[C[x, t], t] == 
  Deff*D[C[x, t], x, x] - (((dens*qmax)/V)*(C[x, t]/(ks + C[x, t]))), 
 C[x, 0] == Ci, C[0, t] == Cs + (Ci - Cs) Exp[-t/5], 
 Derivative[1, 0][C][10, t] == 0}, 
 C[x, t], {x, 0, 10}, {t, 0, 48}, MaxStepSize -> 0.1];
 {Plot3D[Evaluate[C[x, t] /. sol], {x, 0, 10}, {t, 0, 48}, 
   ColorFunction -> "SunsetColors"],
  Plot[Evaluate[C[x1, t1] /. (sol  /. {x -> x1, t -> t1}) ], {x1, 0, 10}],
  Plot[Evaluate[C[x2, t2] /. (sol  /. {x -> x2, t -> t2}) ], {t2, 0, 48}]},
 {{Deff, 7.776*10^-2}, 7.776*10^-8, 7.776, Appearance -> "Labeled"}, 
 {{dens, 0}, 0, 2*10^6, Appearance -> "Labeled"}, 
 {{qmax, 1*10^-8}, 0, 1*10^2, Appearance -> "Labeled"}, 
 {{ks, 1075*10^-2}, 0, 1075*10^2, Appearance -> "Labeled"}, 
 {{V, 3*10^-2}, 3*10^-6, 30, Appearance -> "Labeled"},
 {{Ci, 10}, 0, 50, Appearance -> "Labeled"}, 
 {{Cs, 8.5}, 0, 50, Appearance -> "Labeled"}, 
 {{x2, 0}, 0, 10, Appearance -> "Labeled"},
 {{t1, 0}, 0, 48, Appearance -> "Labeled"}]

Oh, and I changed the color : )

Graphs

$\endgroup$
1
  • $\begingroup$ Thank you so much @PeterRoberge! $\endgroup$ Nov 12, 2015 at 10:44

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.