carljohan6
(Carl-Johan Eliasson)
May 1, 2023, 8:00am
1
Im trying to solve this Differential Equation with Mathematica to see if the result equals the result I got by solving the equation by hand.
However Mathematica gives me an answer with ProductLog which doesn’t make sence to me.
Answer given when solving by hand: y = xLn|((x+y)^2)/(x)| + Cx, where C is constant of integration
Mathematica give you solution with explicit form it’s a general solving diff equation.
EQ = y'[x] == (x^2 + y[x]^2)/(x*y[x] - x^2);
sol = DSolve[EQ, y, x] // Quiet
EQ /. sol[[1]] // FullSimplify(*A correct solution*)
Your solution by hand are implicit form:
Solve[y == x*Log[((x + y)^2)/(x)] + C[1]*x, y] // PowerExpand
(*{{y -> -x -
2 x ProductLog[-(E^(1/2 (-1 - C[1]))/(2 Sqrt[x]))]}, {y -> -x -
2 x ProductLog[E^(1/2 (-1 - C[1]))/(2 Sqrt[x])]}}*)
Regards M.I.
From here give you solution with implicit form(with Solve ),but is very mesy:
On[$Assumptions]; (*shows when $Assumptions is changed*)
Module[{assum = True},
Internal`InheritedBlock[{Solve, $Assumptions}, Unprotect[Solve];
call : Solve[eq_, v_, opts___] /; ! TrueQ[$in] :=
Block[{$in = True, $res1, $res2},
Check[(*Use Check to try default settings& respond to \
messages*)$res1 = call (*try original call*),(*Check[]*)
Print["Trying \"ReduceOptions\" -> \"UseTranscendentalSolve\" -> \
True on ", HoldForm[call]];
With[{redopts = SystemOptions["ReduceOptions"]},
Internal`WithLocalSettings[
SetSystemOptions[
"ReduceOptions" -> "UseTranscendentalSolve" -> True],(*I`WLS:
init*)$res2 = Solve[eq, v, GeneratedParameters -> $S, opts];
$res2 = $res2 /.
ConditionalExpression[e_,
c_] :>(*map condition to assumption*)($Assumptions = \
$Assumptions && c;(*for solvers and Simplify[]*)
assum = assum && c;(*for addConditions[] at end*)e);
Print[
"$Assumptions now ", $Assumptions];(*context for \
On[$Assumptions]*)$res2 = Simplify[$res2];
Print["Result= ", $res2],
SetSystemOptions[
redopts] (*I`WLS:
reset*)];];
If[FreeQ[$res2,
Solve], $res2, $res1],(*Check[]*){Solve::ifun}]];
Protect[Solve];
sol = DSolve[DSolve[y'[x] == (x^2 + y[x]^2)/(x*y[x] - x^2), y, x]];
Print["$Assumptions finally ", $Assumptions];(*context for \
On[$Assumptions]*)sol = sol /. addConditions[assum]]]
Off[$Assumptions];
carljohan6
(Carl-Johan Eliasson)
May 1, 2023, 2:04pm
4
Okay, but when i solve it by hand i make the substitution y = vx, can this be done with mathematica to give the anwer that i get by hand and not the one that explicit one which mathematica gives (ProducLog etc…)
S = DSolveChangeVariables[
Inactive[DSolve][y’ == (x^2 + y ^2)/(x*y - x^2), y, x], v,
x, y == v *x] // FullSimplify
S // Activate
(*{{v -> Function[{x}, -1 -
2 ProductLog[-(1/2) Sqrt[E^(-1 - C[1])/x]]]}, {v ->
Function[{x}, -1 - 2 ProductLog[1/2 Sqrt[E^(-1 - C[1])/x]]]}}*)
Looks the same.
This is a simulation of doing it by hand step-by-step with your substitution:
(y'[x] == (x^2 + y[x]^2)/(x*y[x] - x^2)) /. y -> Function[t, t*v[t]]
Solve[%, v'[x]][[1, 1]] /. Rule -> Equal // Simplify
DivideSides[%, %[[2]] x, GenerateConditions -> False]
ApplySides[Integrate[#, x] &, %]
SubtractSides[%, 0 == C[1]]
% /. v -> Function[t, y[t]/t]
Solve[%, y[x]]