0

I want to solve a DAE-system and I want to vary more than one initial conditions and to manipulate them. I looked here:

Putting NDSolve into ParametricPlot

But it does not work:

alpha = 0.5
beta = 1
sol = ParametricNDSolve[{

   x'[t] == -x[t]*a[t] - 3*x[t] + alpha*y[t]^2 +  1/2*beta*(r1[t]^2 - r2[t]^2), 
   y'[t] == -y[t]*a[t] - alpha*x[t]*y[t], 
   r1'[t] == -r1[t]*a[t] - 3/2*r1[t] + beta*x[t]*r1[t], 
   r2'[t] == -r2[t]*a[t] - 3/2*r2[t] + beta*x[t]*r2[t],
   a[t] == -1/2*(3 - 3*y[t]^2 + 3*x[t]^2),
   x[-10] == b, y[-10] == c, r1[-10] == 0.2, r2[-10] == 0.2},
   {x, y, r1, r2},
  {t, 1, -10}, {b, c}]

Manipulate[
 ParametricPlot[y[c][t] + x[b][t], {t, 0, -5}], {b, 0, 1}, {c, 0, 1}]
lambda1990
  • 69
  • 3

1 Answers1

2

Your functions for y and x are single values and not lists, and thus doing a ParametricPlot for the sum of these is not going to work. However, to solve the equations and get a plot you can run the following:

alpha = 0.5
beta = 1
solf[b_, c_, tp_] := Module[{sol}, 
   sol = NDSolve[{x'[t] == -x[t]*a[t] - 3*x[t] + alpha*y[t]^2 + 
     1/2*beta*(r1[t]^2 - r2[t]^2), 
     y'[t] == -y[t]*a[t] - alpha*x[t]*y[t], 
     r1'[t] == -r1[t]*a[t] - 3/2*r1[t] + beta*x[t]*r1[t], 
     r2'[t] == -r2[t]*a[t] - 3/2*r2[t] + beta*x[t]*r2[t], 
     a[t] == -1/2*(3 - 3*y[t]^2 + 3*x[t]^2), x[-10] == b, y[-10] == c,
     r1[-10] == 0.2, r2[-10] == 0.2}, {x, y, r1, r2}, {t, 1, -10}];
   {x[tp], y[tp], r1[tp], r2[tp]} /. sol[[1]]
]

Manipulate[Plot[Total[solf[b,c,tp][[1;;2]]],{tp,0,-5}],{b,0,1},{c,0,1}]

This will give you a plot of the sum of the first and second functions being solved in the NDsolve routine as seems to be the case in your question (x+y).

If you want to get a ParametricPlot for x and y, you may want to be running ParametricPlot[solf[b,c,tp][[1;;2]],{tp,0,-5},AspectRatio->1] but that's not entirely clear from the question.

Jonathan Shock
  • 3,015
  • 15
  • 24
  • Thank you. I try to untertand this code. I'm new with mathematica. Where does the syntax 'solf[b,c,tp][[1;;2]]' come from? Maybe you could explain a little bit what the Module do there above. Actually I want to be free what to do with x and y. I want also plot x^2+y^2. How to handle this? – lambda1990 May 14 '13 at 19:32
  • @lambda1990 Please do not post comments as "answers". You should see a "Comment" link under Jonathan's answer, which allows you to reply to his answer. I've converted this one for you, but please remember the next time. – rm -rf May 14 '13 at 22:12
  • @lambda1990, in the above, the output of solf[b,c,tp] is a list of the solutions {x[tp], y[tp], r1[tp], r2[tp]} where I've used tp as a dummy variable for t. solf[b,c,tp][[1;;2]] then takes the first to second elements of this list (look up ;; in the documentation). Taking the total of this gives the sum of the first and second elements: x[tp]+y[tp]. The use of Module can be found in the documentation too. These allow you to define functions with local variables and are often used to combine a number of functions together into a single algorithm to solve a problem. – Jonathan Shock May 14 '13 at 23:23