4
$\begingroup$

The question is to find and sketch the solution of the following initial value problem: $$(x-y)dx+(3x+y)dy=0$$ and for $x=3$ we have $y=-2$.

I was able to find an implicit solution using

DSolve[{(x - y[x]) + (3x + y[x]) y'[x] == 0, y[3] == -2}, y[x], x]
Solve[Log[1 + y[x]/x] - 2/(1 + y[x]/x) == -6 - Log[x], y[x]]

Is it possible to plot the implicit solution? I tried using the general solution -

sol = DSolve[(x - y[x]) + (3*x + y[x])*y'[x] == 0, y[x], x]
expr = C[1] /. Solve[sol[[1]], C[1]][[1]] /. {y[x] -> y}

and then

ContourPlot[expr, {x, 0, 5}, {y, -5, 5}]

However, I want to plot

Solve[Log[1 + y[x]/x] - 2/(1 + y[x]/x) == -6 - Log[x], y[x]]
$\endgroup$
  • 1
    $\begingroup$ ContourPlot[ Log[1 + y/x] - 2/(1 + y/x) + 6 + Log[x] == 0, {x, 0, 1}, {y, -2, 1}] ? $\endgroup$ – OkkesDulgerci Feb 26 at 16:26
9
$\begingroup$

The main issue we encounter here is that equation solvig functionality doesn't work quite seamlessly for various types of transcendental functions. However looking at the result of DSolve it appears convenient to introduce a new variable $z=\log(1+\frac{y(x)}{x})$.

z[x] == Log[1+ y[x]/x]

Now we can find the exact solution, setting up the initial condition in terms of z[x], i.e. z[3] == -Log[3]:

z[x]/.First @ DSolve[{0==(x - y[x]) + (3x + y[x])y'[x]/.{
                                         y[x] -> x (Exp[z[x]] - 1),
                                         y'[x] -> D[x(Exp[z[x]] - 1), x]}//Simplify,
                       z[3] == -Log[3]},
                       z[x], x] // Quiet
-6 - Log[x] + ProductLog[2 E^6 x]

that is Log[1+ y[x]/x] == -6 - Log[x] + ProductLog[2 E^6 x] i.e. the solution of our equation is y[x] == f[x] such, that

f[x_] := E^(-6 + ProductLog[2 E^6 x]) - x

because

FullSimplify[x (Exp[-6 - Log[x] + ProductLog[2 E^6 x]] - 1), x > 0]

% // TraditionalForm
 E^(-6 + ProductLog[2 E^6 x]) - x

enter image description here

where W is the Lambert function. Now we can plot the graph of the solution. However since it looks like a straight line, we find an example of a linear function to compare the both graphs. We assume that the graphs intersect at x == 0 and x == 3 and so:

g[x_] = a x + b /. First @ Solve[{ f[0] == b, f[3] == 3 a + b}, {a, b}]
 1/E^6 - ((1 + 2 E^6) x)/(3 E^6)
Plot[{ f[x], g[x]}, {x, 0, 4}, PlotStyle -> {Thick, Dashed}, 
                    Epilog -> {Red, PointSize[0.02], Point[{3, -2}]}]

enter image description here

The graph is very close to a linear function as could be seen from ContourPlot. It might be convenient to plot the difference of the both functions:

Plot[ Re @ f[x] - g[x], {x, -3, 5}, PlotStyle -> {Thick, Magenta}, 
                                    Epilog -> {Red, PointSize[0.02], Point[{3, 0}]}]

enter image description here

For completeness we plot the real and imaginary values of f[x] since it becomes complex for negative numbers (this is independendent from the physical (?) model discribed by the original equation)

Plot[ Flatten @ {ReIm @ f[x], g[x]}, {x, -20, 20}, 
        PlotStyle -> {Thick, Thick, Dashed}, Evaluated -> True, 
        Epilog -> {Red, PointSize[0.01], Point[{3, -2}]}]

enter image description here

|improve this answer|||||
$\endgroup$

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.