3
$\begingroup$

I tried plotting the following functions.

s = With[{p = 70., q = 100., r = 100., c = 10.},  NDSolve[{z'[x] == r - (c/(1 + y[x])),  y'[x] == (p - y[x] (q + c/(1. + y[x])))/(z[x]) - (y[x] z'[x])/ z[x], z[0] == 200., y[0] == 0.}, {z, y}, {x, 0, 20000}]]

Plot[Evaluate[{y[x], 0.35 - 14000 ((100 x + 200)^(-2)),  0.35 - 32679.166 ((92.593 x + 200)^(-2.1599))} /. s], {x, 0,  20000}, PlotStyle -> Automatic]

But after plotting, the y-axis is displaying a single value 0.35.

I tried including PlotRange as:

Plot[Evaluate[{y[x], 0.35 - 14000 ((100 x + 200)^(-2)),  0.35 - 32679.166 ((92.593 x + 200)^(-2.1599))} /. s], {x, 0,  20000}, PlotRange -> {All, {0.1, 0.35}},PlotStyle -> Automatic]

But, this code changed the nature of the curves though displayed the y-axis values correctly.

$\endgroup$
4
  • 1
    $\begingroup$ Try doing the Evaluate on a separate line and just feed Plot the final function, not an expression that resolves to the final function $\endgroup$ Commented Jul 17, 2022 at 11:40
  • 1
    $\begingroup$ With {y[0],y[1],y[10],y[100],y[1000],y[10000]}/.s I get {{0.,0.196555,0.341764,0.349918,0.349999,0.35}} meaning, if we trust the output NDSolve for the moment, that $y(x)$ seems to converge to $0.35$ as $x \to \infty$. It is very close to $0.35$ already for $x=10$, and your plot interval {x,0,20000} is huge. The other two functions that you plot are also close to $0.35$. Therefore, why does the plot surprise you? Try changing the plot interval to {x,0,10}. $\endgroup$
    – user293787
    Commented Jul 17, 2022 at 11:44
  • 1
    $\begingroup$ All the change in your function happens at very low values of x, up to $x=20$ or so. When you plot up to $x=20000$, the changing parts are compressed against the y axis and invisible. Use a smaller range of x to see the changes. $\endgroup$
    – MarcoB
    Commented Jul 17, 2022 at 11:45
  • $\begingroup$ Thanks a lot. I got the point. $\endgroup$
    – Isha Arora
    Commented Jul 17, 2022 at 13:04

1 Answer 1

2
$\begingroup$

Use of the option ScalingFunctions will force finer graduation in the ticks.

$Version

"13.1.0 for Mac OS X x86 (64-bit) (June 16, 2022)"

Clear["Global`*"]

s = With[{p = 70, q = 100, r = 100, c = 10},
   NDSolve[{z'[x] == r - (c/(1 + y[x])),
     y'[x] == (p - y[x] (q + c/(1 + y[x])))/(z[x]) - (y[x] z'[x])/z[x],
     z[0] == 200, y[0] == 0}, {z, y}, {x, 0, 20000}]];

Plot[Evaluate[
  SetPrecision[{
     y[x],
     0.35 - 14000 ((100 x + 200)^(-2)),
     0.35 - 32679.166 ((92.593 x + 200)^(-2.1599))} /. s, 15]],
 {x, 0, 20000},
 PlotStyle -> {Automatic, Automatic, Dashed},
 PlotLegends -> Placed[Automatic, {0.6, 0.5}],
 ScalingFunctions -> {Exp, Log},
 WorkingPrecision -> 15]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks a lot. This has resolved my problem. As, I am new to Mathematica, please could you explain why exponential and log are used for ScalingFunctions? $\endgroup$
    – Isha Arora
    Commented Jul 17, 2022 at 13:01
  • 1
    $\begingroup$ The scale factors are a pair comprised of a function and its inverse. You just need to use a nonlinear scale to get Mathematica to change the tick labels. Either {Log, Exp} or {Exp, Log} would work. The very limited range makes the nonlinear scale look linear. The WorkingPrecision is used to suppress some unnecessary trailing zeroes in the tick labels. $\endgroup$
    – Bob Hanlon
    Commented Jul 17, 2022 at 13:20

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