0
$\begingroup$

I`m trying to solve the following system of non-linear coupled first-order ordinary differential equations: $$ \frac{dh}{dx}=-h^2c^2 $$ $$ \frac{dc}{dx}=-hc $$ with the conditions: $$h(5)=5, c(5)=0.79e^{-12.5}$$

Using NDSolve I tried to plot the solution for $h$:

 In[1]:= Clear[x]
         sol = NDSolve[{h'[x] == -h[x]^2c[x]^2+1, c'[x] == -h[x]c[x],h[5] == 5, c[5] == 0.79Exp[-12.5] }, {h, c}, {x, -10, 10}]
          Plot[Evaluate[{{h[x]} /. sol}], {x, -10, 10},PlotRange -> All]

But unfortunately, I didn`t see a graph, only an empty plot appeared, and error messages before the plot:

NDSolve::dsvar: -9.99959 cannot be used as a variable.
NDSolve::dsvar: -9.99959 cannot be used as a variable.
NDSolve::dsvar: -9.59143 cannot be used as a variable.
General::stop: Further output of NDSolve::dsvar will be suppressed during this calculation.

enter image description here

How to solve this, so the plot will generate a graph corresponding to the solution of the equations?

$\endgroup$
7
  • $\begingroup$ Range \[Rightarrow] All should be PlotRange -> All. Please don't use math assistent to input the right arrow, simply type -> is the right way to go. Also, the system becomes stiff at x == -0.266228 as mentioned in the warning. If it should not be stiff, please double check if the system itself is correct. $\endgroup$
    – xzczd
    Commented Jan 25, 2023 at 9:49
  • $\begingroup$ It's PlotRange, not Range. And, please don't add bugs until the community has confirmed it. $\endgroup$
    – xzczd
    Commented Jan 25, 2023 at 9:54
  • $\begingroup$ ok thank you, but there is other problem poping it after I edited my post $\endgroup$ Commented Jan 25, 2023 at 9:54
  • 2
    $\begingroup$ This time your variable (probably x) is polluted. Please always pay attention to the color of variable. If it's empty, it'll (in most cases) be blue, otherwise it's black. Execute Clear[x, c, h, Derivative] to remove the pollution. $\endgroup$
    – xzczd
    Commented Jan 25, 2023 at 10:22
  • 1
    $\begingroup$ @Daniel Vainshtein I`m quite sure that changing the range might help. See my answer. $\endgroup$ Commented Jan 25, 2023 at 10:32

1 Answer 1

1
$\begingroup$

Using the solution range provided by NDSolve try:

{xmin, xmax} = (h   /. sol[[1]])["Domain"][[1]];(*{-0.266228, 10.}*)
Plot[Evaluate[{{h[x]} /. sol}], {x, xmin, xmax} ]

enter image description here

Hope it helps!

$\endgroup$
1

Not the answer you're looking for? Browse other questions tagged or ask your own question.