# Obtain constant from DSolve [closed]

I need to extract constant C from expression which I get when solve equation. i.e.

DSolve[y'[x]==1/(2x),y[x],x]


In result Mathematica gives me this one

y[x]->C+1/2 Log[x]


But I want something like this

C=x Exp[-2y]


I'll try to use DSolve.Constant[] (sound like exactly what I want, but isn't working unfortunately) Please, help me.

• So, transform the rule to an equation and Solve it. You can transform it using the prediction interface of Mathematica – Sektor Jul 1 '15 at 6:37
• @Sektor Thanks. I did it. sol = DSolveValue[y'[x] - 1/(2x) == 0, y[x], x] Solve[y[x] == sol, C] – PilgrimViis Jul 1 '15 at 7:32
• Or: Solve[Keys[#] == Values[#] &[DSolve[y'[x] == 1/(2 x), y[x], x]], C] – Mariusz Iwaniuk Jul 3 '15 at 15:35

       expr1 = y[x] -> C + 1/2 Log[x]

(*   y[x] -> C + Log[x]/2   *)

expr2 = expr1[] == y

(*    C + Log[x]/2 == y  *)

expr3 = Map[Subtract[#, Log[x]/2] &, expr2]

(*  C == y - Log[x]/2  *)

Map[Exp, expr3] /. E^C -> C2

(*     C2 == E^y/Sqrt[x]    *)


Have fun!

• This only answers the question in this specific case. Which the OP has already done by hand. – Myridium Jul 1 '15 at 8:19
• @Myridium 6 Of course. But this is also the way in a more complex case, and no general solution at all. – Alexei Boulbitch Jul 1 '15 at 14:51
• @PilgrimViis demonstrated a general solution. – Myridium Jul 1 '15 at 15:21
• @ Myridium No, he did not. It is just an illusion. In a general case equation for C  may be a transcendental one, Solve  returning nothing in that case. But the point is that one in reality needs no such general solution, but a reasonable case by case consideration. – Alexei Boulbitch Jul 2 '15 at 7:24