Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

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!

share|improve this question

marked as duplicate by Sjoerd C. de Vries, Yves Klett, Artes, m_goldberg, Kuba Sep 3 '13 at 21:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Closely related: (3175), (6669), (9035) –  Mr.Wizard Sep 3 '13 at 16:19
Plot prints table of values..NDSolve returns O2n[ro]->Something...check Table[O2n[r]) /. s, {r, rn, ro}] are replacing your dependent variable with your independent variable which you have liberty to assign. –  Rorschach Sep 3 '13 at 16:51
Ah cheers - ReplaceAll documentation not very illuminating coming from a MATLAB background, but that link is helpful. Thanks! –  DRG Sep 3 '13 at 16:52
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. –  Yves Klett Sep 3 '13 at 17:35

Browse other questions tagged or ask your own question.