I have solved an ODE with NDSolve, and put the result in S:

S = NDSolve[{y'[x]==(y[x]^4+y[x]+1)^(1/2),y[0]==0}, y, {x, 0, 100}]

But i don't want to plot y[x] directly. I want to define a new function of y[x] and plot that function. So i tried this:

func1[x_] := (Evaluate[y[x]/.S])^-3;
Plot[func1[x], {x, 0, 100}]

But that doesn't work! I understand why this should be wrong but i don't know what's the correct way to do this.

  • $\begingroup$ What do you mean by "that doesn't work"? It produces a plot for me. I do get an error about your differential equations, but the basic syntax you have is fine $\endgroup$ – Jason B. Nov 24 '15 at 9:36
  • $\begingroup$ @JasonB Actually i have simplified my ODE here a little. And you're right, i tested it now and i got a result too. But i still can't get the result from my original ODE. i get an error like this on defining the new function: SetDelayed::write: "Tag Times in (2.27621*10^-27/(y^3))[m_] is Protected. Now at least i know the problem is not with the syntax. thanks. $\endgroup$ – Mostafa Nov 24 '15 at 9:55
  • $\begingroup$ You forgot to clear previous definitions if you're hitting that error. Look up Clear[]. $\endgroup$ – J. M.'s ennui Nov 24 '15 at 10:04
  • $\begingroup$ @JasonB Oh, thanks a lot. That solved the problem. $\endgroup$ – Mostafa Nov 24 '15 at 10:28

This works:


enter image description here Often times you need to ensure your definition of func1 is only used when x has a numeric value. In that case use

func1[x_?NumericQ] := ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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