1
$\begingroup$

I'm having trouble understanding this Mathematica syntax.

if I do

y[x] /. DSolve[{y'[x] == y[x], y[0] == 1}, y[x], x]

I'd expect that I now have a function $y(x) = e^x$, such that when I write

y[0] or even N[y[0]] that I should get 1, but Mathematica won't evaluate it and instead writes y[0]

Why? And how can I create a real mathematica function y[x] = e^x from the DSolve Function

$\endgroup$
5
  • 1
    $\begingroup$ You can do this % /. x -> 0 $\endgroup$
    – zhk
    May 17, 2017 at 16:31
  • 1
    $\begingroup$ For a function, y[x_] = Flatten[%] and then try y[0]. $\endgroup$
    – zhk
    May 17, 2017 at 16:35
  • $\begingroup$ ok I'll give that a try. $\endgroup$
    – Xaser
    May 17, 2017 at 16:35
  • $\begingroup$ y /. DSolve[{y'[x] == y[x], y[0] == 1}, y, x]? $\endgroup$
    – Michael E2
    May 17, 2017 at 16:41
  • $\begingroup$ Duplicate Confirmed, sorry, didn't come across that post for some reason, even though this obvious title. $\endgroup$
    – Xaser
    May 17, 2017 at 16:43

1 Answer 1

1
$\begingroup$
 In[1]:= y1[x_] = 
 y[x] /. First[DSolve[{y'[x] == y[x], y[0] == 1}, y[x], x]]

Out[1]= E^x

In[2]:= y1[0]

Out[2]= 1
$\endgroup$
2
  • $\begingroup$ No its not different. I finished typing it in and then saw your comment :) I can remove it if you want. $\endgroup$
    – Lotus
    May 17, 2017 at 16:39
  • $\begingroup$ This works. I couldn't get @zhk 's comment to work, however I guess that's just due to my incompetence. I think however that Lotus was first, just took more time to write the answer down, so he gets the accepted answer. $\endgroup$
    – Xaser
    May 17, 2017 at 16:42

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