3

I want to ParametricPlot the solution to a differential equation for which an initial value ranges from 1 to 10.

The problem (I believe) is that I don't know how to pass a single solution from a list into DSolve. Here is my code:

ClearAll[x, y, t, i]
equations = {x'[t] == y[t], 
   y'[t] == -10 x[t] + 3 y[t], x[0] == #, 
    y[0] == 0} & /@ Range[1, 10]
SolvePlot[z_] := (solution = DSolve[equations[[i]], {x[t], y[t]}, t]; 
  ParametricPlot[{x[t], y[t]} /. solution, {t, 0, 4}])
For[i = 1, i <= 10, i = i + 1, SolvePlot[i]]

Can someone help me out? Thank you!

corey979
  • 23,947
  • 7
  • 58
  • 101
  • 1
    Perhaps you want Table instead of For. For generates no output; see also http://mathematica.stackexchange.com/questions/134609/why-should-i-avoid-the-for-loop-in-mathematica – Michael E2 Jan 17 '17 at 19:05

1 Answers1

4

You can do it easily in NDSolve availing ?NumericQ.

soln[x0_?NumericQ] := 
      First@NDSolve[{x'[t] == y[t], y'[t] == -10  x[t] + 3  y[t], 
         x[0] == x0, y[0] == 0}, {x, y}, {t, 0, 10}];
ParametricPlot[
 Evaluate[{x[t], y[t]} /. soln[#] & /@ Range[1, 10, 1]], {t, 0, 10}, 
 PlotRange -> All, MaxRecursion -> 8, AxesLabel -> {"x", "y"}]

enter image description here

If you want to stick to DSolve then you have to relay on DSolveValue?

{sol1, sol2} = 
  DSolveValue[{x'[t] == y[t], y'[t] == -10  x[t] + 3  y[t], 
    x[0] == x0, y[0] == 0}, {x, y}, t];
ParametricPlot[
 Evaluate[Table[{sol1[t], sol2[t]} /. {x0 -> m}, {m, 1, 10, 1}]], {t, 
  0, 10}, PlotRange -> All]
zhk
  • 11,939
  • 1
  • 22
  • 38