Message Boards Message Boards

Visualize a parametric plot with two functions?

Posted 8 years ago

Hi all, I'm relatively new to Mathematica, and am trying to make a parametric plot. I have an InterpolatingFunction (generated from NDSolve) that I am trying to plot against another function (generated by integrating the first). I can plot the two functions alone, but the parametric plot comes up blank. Here is the code I'm running:

s = NDSolve[{Derivative[1][g][t] == -(2.3*10^-18)*(0.000085` g[t]^6 + 0.3` g[t]^5 + 0.7` g[t]^2)^0.5`, g[0] == 10^50}, g, {t, 0, 2.3*10^18}]
fn = Integrate[(g[t] /. s), {t, x, 2.3*10^18}]
Plot[Evaluate[g[x] /. s], {x, 0, 10^18}, PlotRange -> All]
Plot[fn, {x, 0, 2.3*10^18}, PlotRange -> All]
ParametricPlot[{Evaluate[g[x] /. s] - 1, fn[x]}, {x, 0, 2.3*10^18}]

I'm trying to plot the g function on the x-axis and the "fn" function on the y-axis. Any ideas? Thanks very much.

POSTED BY: Erik Rosenberg

Your s is a list of lists: you had better get rid of the outer list. Moreover, your fn contains already x implicitly: do not add the extra x in fn[x]. The following code works:

s = NDSolve[{Derivative[1][g][
      t] == -(2.3*10^-18)*(0.000085` g[t]^6 + 0.3` g[t]^5 + 
         0.7` g[t]^2)^0.5`, g[0] == 10^50}, 
   g, {t, 0, 2.3*10^18}][[1]]
fn = Integrate[(g[t] /. s), {t, x, 2.3*10^18}]
Plot[Evaluate[g[x] /. s], {x, 0, 10^18}, PlotRange -> All]
Plot[fn, {x, 0, 2.3*10^18}, PlotRange -> All]
ParametricPlot[Evaluate[{(g[x] /. s) - 1, fn}], {x, 0, 2.3*10^18}, 
 PlotRange -> All]

However, I would rather use NDSolveValue and avoid those Evaluate and replacements:

Clear[x, t, g, fn];
g = NDSolveValue[{g'[
     t] == -(2.3*10^-18)*(0.000085` g[t]^6 + 0.3` g[t]^5 + 
        0.7` g[t]^2)^0.5`, g[0] == 10^50}, g, {t, 0, 2.3*10^18}]
fn[x_] := Integrate[g[t], {t, x, 2.3*10^18}]
Plot[g[x], {x, 0, 10^18}, PlotRange -> All]
Plot[fn[x], {x, 0, 2.3*10^18}, PlotRange -> All]
ParametricPlot[{g[x] - 1, fn[x]}, {x, 0, 2.3*10^18}, PlotRange -> All,
  AspectRatio -> 1]
POSTED BY: Gianluca Gorni
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