3
$\begingroup$

DSolve gives a strange solution for the Riccati differential equation $ y' = (y^2) - 2 x^2 y + (x^4) + 2 x + 4 $

Opres = DSolve[y'[x] == y[x]^2-2x^2*y[x]+x^4+2x+4, y[x], x]

$\left\{\left\{y(x)\to \frac{1}{c_1 e^{4 i x}-\frac{i}{4}}+x^2-2 i\right\}\right\}$

When I try plot this solution

Opresgraf = 
 Plot[Evaluate[y[x] /. Opres /. C[1] -> Range[-3, 3]], {x, -4.7, 4.7}, 
  PlotRange -> 4.7]

I get a blank graph.

My question is: how can I get a solution with DSolve (not with NDSolve, because in my student research project I need DSolve) and plot that solution, the most important is to plot that general solution with DSolve.

$\endgroup$
2
  • 1
    $\begingroup$ You can't plot a complex expression. You need to either plot its real value, its imaginary value or its modulus. Also you have a typo in the input, you need y[x] not y in the ODE itself. $\endgroup$
    – Nasser
    Nov 27, 2018 at 18:24
  • 1
    $\begingroup$ Is Range[-3.3] supposed to be Range[-3,3]? $\endgroup$ Nov 27, 2018 at 18:26

4 Answers 4

8
$\begingroup$

perhaps

Plot[Evaluate[ReIm@y[x] /. (Opres /. C[1] -> Range[-3, 3])], {x, -4.7, 4.7}, 
  PlotRange -> 4.7]

enter image description here

$\endgroup$
1
  • $\begingroup$ But is the solution of d.e only real , will y[x]-> Complex even be solution of d.e and what will be Derivate of that y[x] complex ? $\endgroup$ Dec 2, 2018 at 0:18
5
$\begingroup$

With a single graph you can only plot those solution that are imaginary or real.

There are 2 real ones:

sol = First[DSolve[y'[x] == y[x]^2 - 2 x^2*y[x] + x^4 + 2 x + 4, y[x], x]];
zeroIm = FullSimplify[ComplexExpand[Im[y[x] /. sol]]] == 0 // Solve[#, C[1]] &

$\style{text-decoration:line-through}{\left\{\left\{C[1]\to -\frac{1}{4}\right\},\left\{C[1]\to \frac{1}{4}\right\}\right\}}$

I forgot to consider complex values of C[1]:

sol = First[DSolve[y'[x] == y[x]^2 - 2 x^2*y[x] + x^4 + 2 x + 4, y[x], x]];
zeroIm = Numerator[FullSimplify[ComplexExpand[Im[y[x] /. sol], C[1]]]] == 0

(* -2 + 32 Abs[C[1]]^2 == 0 *)

which is the equation of a circle of real solutions:

Manipulate[Plot[Evaluate[y[x] /. sol /. C[1] -> Sqrt[1/16] (Cos[t] + I Sin[t])],
               {x, -4.7, 4.7}, Exclusions -> All], {t, 0, 2 π}]

Code for GIF-animation:

n = 70;
pics = Table[Rasterize[#, "Image"] & @ Plot[
        Evaluate[y[x] /. sol /. C[1] -> Sqrt[1/16] (Cos[t] + I Sin[t])], {x, -4.7, 4.7},
        PlotRange -> {{-4.7, 4.7}, {-30, 46}}, ImageSize -> {500, 300}, AspectRatio -> Full,
        PlotRangePadding -> None, PlotRangeClipping -> True,
        ClippingStyle -> False], {t, 0, 2 π - #, #}] &[2 π/n];
Export["asd.gif", pics, "AnimationRepetitions" -> ∞,
        "ColorMapLength" -> 16, "DisplayDurations" -> ConstantArray[0.04, n]]
$\endgroup$
2
  • $\begingroup$ With what function you get that last graph ? $\endgroup$ Dec 2, 2018 at 1:46
  • $\begingroup$ @МилошВучковић I haven't saved it but I have added something similar except for adding the text row to the images. $\endgroup$
    – Coolwater
    Dec 3, 2018 at 11:04
3
$\begingroup$

Try this

Opres = DSolve[y'[x] == y[x]^2-2x^2 *y[x]+x^4+2x+4, y[x], x][[1]];
Plot[{Re[y[x]/.Opres/.C[1]->Range[3.3]],Im[y[x]/.Opres/.C[1]->Range[3.3]]}, {x,-4.7,4.7}] 
$\endgroup$
2
$\begingroup$

The general solution is not real valued. Try setting an initial condition:

FullSimplify[
 DSolve[{y'[x] == y[x]^2 - 2 x^2*y[x] + x^4 + 2 x + 4, y[0] == 1}, 
   y[x], x]
]

yielding

{{y[x] -> -2 I + (4 + 8 I)/((2 - I) + (2 + I) E^(4 I x)) + x^2}}

which is not real valued (almost everywhere). However, for a different initial condition

FullSimplify[
  DSolve[{y'[x] == y[x]^2 - 2 x^2*y[x] + x^4 + 2 x + 4, y[0] == 0}, 
    y[x], x]
]

{{y[x] -> x^2 + 2 Tan[2 x]}}

the solution is real valued.

We can use a symbolic initial condition

FullSimplify[
  DSolve[{y'[x] == y[x]^2 - 2 x^2*y[x] + x^4 + 2 x + 4, y[0] == c}, 
    y[x], x]
]

{{y[x] -> -2 I + (8 - 4 I c)/(-2 I - c + (-2 I + c) E^(4 I x)) + x^2}}

and see that this complex valued behaviour is generic, but can be hidden with particular choices of the initial condition, c. Note that we can give the initial condition at a different value of the independent variable, and get different behaviour altogether. In fact, providing an initial condition at x=1 gives a real valued generic solution.

FullSimplify[
  DSolve[{y'[x] == y[x]^2 - 2 x^2*y[x] + x^4 + 2 x + 4, y[1] == c}, 
    y[x], x]
]

{{ y[x] -> ( 2 (-1 + c + x^2) Cos[2 - 2 x] + (-4 + (-1 + c) x^2) Sin[2 - 2 x] )/
  ( 2 Cos[2 - 2 x] + (-1 + c) Sin[2 - 2 x] ) }}

Plot[Table[y[x] /. %[[1]], {c, -2, 2}], {x, -2, 2}]

Plot of several particular solutions.


Starting over in full generality, we can get an unintelligible plot.

genSol = FullSimplify[ ComplexExpand[
  y[x] /. DSolve[{
    y'[x] == y[x]^2 - 2 x^2*y[x] + x^4 + 2 x + 4, 
    y[d] == c}, 
    y[x], x][[1]]
]];
Plot[Flatten[
  Table[genSol, {c, -20, 20, 10}, {d, -2, 2, 1}
  ], 1], {x, -4, 4}]

Much too busy plot

Here we have applied the generic initial condition $y(d) = c$ (via y[d] == c) so that we have labels for the parts of a point of a particular solution. Since we only want real solutions, we want $c$, $d$, and $x$ to be real. Applying ComplexExpand[] treats all the variables as if they are real, yielding real solutions passing through the point $(c,d)$. (The largest effect here is that the complex exponentials are rewritten in terms of sine and cosine.)

$\endgroup$
10
  • $\begingroup$ And is this on the end "REAL" GENERAL SOLUTION which will include all reals solution that that General solution ? $\endgroup$ Dec 11, 2018 at 6:10
  • $\begingroup$ No. As explained, setting different y[d]==c will produce different solutions. The last one has d fixed at 1. Varying both c and d at once will produce all the real solutions and also yield an unintelligible graph. I'll add more about this. $\endgroup$ Dec 11, 2018 at 18:31
  • $\begingroup$ Wait, you took for c , -20,-10,0,10,20 and for d -2,-1,0,1,2 ? And for that how we know fore sure that will be for all that c and d reals solutions and what we get with this ? It's just many real solutions, but still not all real solutions--> General Solutions ? $\endgroup$ Dec 12, 2018 at 17:12
  • $\begingroup$ @МилошВучковић : Every real solution passes through at least one real point of the plane. Consequently, varying c and d through every real point of the plane will produce every solution (with infinitely many repetitions since every point on any particular solution is one of the initial conditions). Have you looked at genSol in the addendum? That's as general a solution as you're going to get but it is not what you asked for in your question. $\endgroup$ Dec 12, 2018 at 17:23
  • 1
    $\begingroup$ @МилошВучковић : The last picture is a smpling of real solutions. A graph of all real solutions is a solid plane since every point is a point on a particular solution. $\endgroup$ Dec 13, 2018 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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