0
$\begingroup$

I have an analytical approximation method for solving an ODE and want to compare this to an NDSolve solution, but the syntax is confusing me. To get the solution from NDSolve, I define the ODE as eqn and use the following command to solve for O2n;

s = NDSolve[{eqn == 0, O2n[rn] == 0, O2n[ro] == po/omega}, 
  O2n, {r, rn, ro}]

Af = Plot[{(O2n[r]) /. s}, {r, rn, ro}, PlotStyle -> {Blue}, 
  PlotLegends -> LineLegend[{"Numerical"}]]

This works fine, but the /. syntax confuses me a little - what exactly does it signify, and how can I manipulate this? Specifically, I want to subtract my analytical function p[r] from this solution over the same range (rn - ro) to see how much they differ. Ideally I'd like to be able to export this data and analyze it further - can anyone explain the syntax to me, and how I might go about comparing the twain? Thank you!

$\endgroup$
5
  • $\begingroup$ Closely related: (3175), (6669), (9035) $\endgroup$
    – Mr.Wizard
    Sep 3, 2013 at 16:19
  • 1
    $\begingroup$ ...and what-are-the-most-common-pitfalls-awaiting-new-users $\endgroup$ Sep 3, 2013 at 16:45
  • $\begingroup$ Plot prints table of values..NDSolve returns O2n[ro]->Something...check Table[O2n[r]) /. s, {r, rn, ro}]..you are replacing your dependent variable with your independent variable which you have liberty to assign. $\endgroup$ Sep 3, 2013 at 16:51
  • $\begingroup$ Ah cheers - ReplaceAll documentation not very illuminating coming from a MATLAB background, but that link is helpful. Thanks! $\endgroup$
    – DRG
    Sep 3, 2013 at 16:52
  • $\begingroup$ I guess you are asking two questions, one of which is a candidate for closure (namely the ReplaceAll part)... to answer your second part (perhaps after an edit or another question), working code would be very useful. $\endgroup$
    – Yves Klett
    Sep 3, 2013 at 17:35

0

Browse other questions tagged or ask your own question.