0
$\begingroup$

I have the following code that gives you a phase portrait of a 2d system and I can't understand what means the 3rd and 4th line (sol1 and sol2).

sys = {x'[t] == 3 x[t], y'[t] == -y[t]};

ss = DSolve[sys, {x[t], y[t]}, t];

sol1 = ss[[1, 1, 2]];

sol2 = ss[[1, 2, 2]];

toplot = Flatten[
  Table[{sol1, sol2} /. {C[1] -> i, C[2] -> j}, 
    {i, -0.5, 0.5, 0.25}, {j, -0.5, 0.5, 0.25}], 1]

graphs = ParametricPlot[Evaluate[toplot], {t, -3, 3}]

I searched the documentation but I couldn't figure it out. Thank you.

@J.M. @belisarius I try to extend it in non linear eqiations. I tried another example with a non linear diff eq. What I wanted to find was the phase space. When I put μ>0 then it plots a solution, but it does not show the other fixed point that is non stable. For everything else μ it does not do anything.

sol = NDSolve[{x'[t] == μ - x[t]^2, y'[t] == -y[t], x[0] == x0, y[0] == y0}, {x[t], y[t]}, {t, 0, 100}]

toplot = Table[{x@t, y@t} /. sol, {x0, -.5, 2, .25}, {y0, -.5, .5, .25}];

ParametricPlot[Evaluate[toplot], {t, 0, 100}, PlotRange -> All]

I now the dynamics of the above, I do not want you to explain that to me. I want your help because I am trying to learn mathematica.

$\endgroup$
8
  • 1
    $\begingroup$ It's for extracting the (approximate) solutions, though I think it's a bit cumbersome, and I prefer using {sol1, sol2} = {x, y} /. First[ss]; $\endgroup$ Apr 23, 2013 at 18:39
  • 1
    $\begingroup$ @J.M. {x@t, y@t} /. First[ss] in this case $\endgroup$ Apr 23, 2013 at 18:42
  • $\begingroup$ thank you very much! can you explain me or send me any link that explains what x@t means? $\endgroup$
    – 2island
    Apr 23, 2013 at 18:45
  • $\begingroup$ @bel, blah, I'm too used to not including the arguments for the functions... 2island, the double bracket syntax is shorthand for Part[]. You will want to look this up in the docs. Additionally, x[t], x @ t, and t // x all mean the same thing; that is, applying the function x to the argument t. $\endgroup$ Apr 23, 2013 at 18:45
  • 2
    $\begingroup$ For future reference on how to figure these things out: search the docs for [[ and it'll take you to Part which explains the syntax used in the line sol1 = .... The meaning of @ is a bit more difficult to discover. Searching for it takes you to Prefix, but here's a more relevant doc page. $\endgroup$
    – Szabolcs
    Apr 23, 2013 at 18:53

1 Answer 1

1
$\begingroup$
ss = DSolve[{x'[t] == 3 x[t], y'[t] == -y[t], x[0] == x0, y[0] == y0}, {x, y}, t];
toplot = Table[{x@t, y@t} /. ss, {x0, -0.5, 0.5, 0.25}, {y0, -0.5, 0.5, 0.25}];
ParametricPlot[Evaluate[toplot], {t, -1, 1}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Is it right to use the NDSolve (when u want to treat with a non linear diff eq) and as initial cond put variables as above? Plot[r (1 - r^2), {r, 0, 1}, AxesLabel -> {r, r'}] ssa = NDSolve[{r'[t] == r[t] (1 - r[t]^2), u'[t] == 1, r[0] == r0, u[0] == u0}, {r[t], u[t]}, {t, 0, 100}] toplot = Table[{r@t Cos[u@t], r@t Sin[u@t]} /. ssa, {r0, -.5, .5, 0.25}, {u0, -.5, .5, 0.25}]; ParametricPlot[toplot, {t, 0, 100}] The solution seems right but it opens a message that says that initial cond r0 is not a number or rectangular array of numbers. $\endgroup$
    – 2island
    Apr 24, 2013 at 9:49
  • $\begingroup$ @2island You must plug in numbers in NDSolve[], not symbolic constants $\endgroup$ Apr 24, 2013 at 11:59

Your Answer

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

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