# Obtain constant from DSolve [closed]

I need to extract constant C[1] 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]+1/2 Log[x]


But I want something like this

C[1]=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[1]] – PilgrimViis Jul 1 '15 at 7:32
• Or: Solve[Keys[#] == Values[#] &[DSolve[y'[x] == 1/(2 x), y[x], x]], C[1]] – Mariusz Iwaniuk Jul 3 '15 at 15:35

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

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

expr2 = expr1[[2]] == y

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

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

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

Map[Exp, expr3] /. E^C[1] -> 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[1]  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