1
$\begingroup$

I am trying to solve a equation graphically but the plot doesn't display anything...

eqn = K == (Cc + x)/((Ca - 2 x)^2 (Cb - x))
const = {K -> 0.016, Ca -> 42, Cb -> 28, Cc -> 4}
f[x_] = eqn /. const
Plot[f[x], {x, 0, 20}]

I tried with Plot, but it doesn't work, how can I solve it graphically?

$\endgroup$
  • $\begingroup$ f = eqn /. const and Plot[f, {x, 0, 20}], or leave f[x_] as is and use Plot[Evaluate[f[x]], {x, 0, 20}]. $\endgroup$ – AccidentalFourierTransform Apr 25 '18 at 21:40
  • $\begingroup$ @AccidentalFourierTransform and that's all I have to do to solve it graphycally? Or there are others steps? $\endgroup$ – Darius Ionut Apr 25 '18 at 21:51
5
$\begingroup$
eqn = K == (Cc + x)/((Ca - 2 x)^2 (Cb - x));
const = {K -> 0.016 // Rationalize, Ca -> 42, Cb -> 28, Cc -> 4};
f[x_] = eqn /. const;

plt = Plot[Evaluate@f[x], {x, 0, 20}, MaxRecursion -> 5]

enter image description here

Finding the x-value of the point on the plot line that is closest to y == 0

SortBy[Cases[plt, Line[pts_] :> pts, Infinity][[1]], Abs[#[[2]]] &][[1, 1]]

(* 15.9261 *)

Compare with the actual root

Solve[f[x], x, Reals][[1]] // N

(* {x -> 15.923} *)
| improve this answer | |
$\endgroup$
2
$\begingroup$

This is another approach in which is plotted the crossing-point with MeshFunction, and extract that point:

eqn = K == (Cc + x)/((Ca - 2 x)^2 (Cb - x));
const = {K -> 0.016 // Rationalize, Ca -> 42, Cb -> 28, Cc -> 4};
f[x_] = eqn /. const

$$\frac{2}{125}=\frac{x+4}{(42-2 x)^2 (28-x)}$$

plt = Plot[Evaluate@f[x], {x, 0, 20}, MaxRecursion -> 5, Mesh -> {{0.}}, 
MeshFunctions -> Function[{x}, -(2/125) + (4 + x)/((42 - 2 x)^2 (28 - x))], 
Frame -> True, 
MeshStyle -> {{Red, PointSize[Medium]}, {Green, PointSize[Medium]}}]

enter image description here

Cases[plt[[1, 1, 1]], {a_, b_} /; Abs[b] < 10^-6]

{{15.923, -1.13533*10^-7}}

| improve this answer | |
$\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.