Message Boards Message Boards

0
|
2378 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

Animation of PDE using ParametricPlot

Posted 11 years ago
Hola!
I was using Mathematica to visualise trajectories of x,y depending on p.  ¿Is it possible?
Talking about "it's simple to animate the parametric plot of them by using ParametricPlot inside Animate."
But I cannot animate the NDSolve using ParametricPlot.Can you please tell me why I get errors like "NDSolve::dsvar: 1.0011952113073699` cannot be used as a variable. ":
Animate[ParametricPlot[{Evaluate[{y[p], x[p]} /. sol = NDSolve[...some equation type D[f1[x[p],y[p],p] = -D[x[p], p],f2[x[p],y[p],p] = -D[y[p], p] x[1] == -1, y[1] == -1}, {y[p], x[p]}, {p, 1, Tp}]]},{p, 1, Tp}], {Tp, 1, 100}]

Thank you!
POSTED BY: Liu Tu
This is an issue with the order of operations in your code.

The best way to solve this is break your code into small manageable functions. When you write code, try to make simple functions which return values and test to see whether these functions work. Breaking up code in this way is a important skill for manageable and debuggable code. 

Here is a function that returns an InterpolationFunction for a given value of some parameter:
functionMaker[param_?NumericQ] := Module[{y, x},  y /. First@NDSolve[{y'[x] == y[x] Cos[x + param y[x]], y[0] == 1}, y, {x, 0, 30}]]

The Module is there to localize y and x. Please see this article on why ?NumericQ was used in the definition of functionMaker. This function can be tested and we can verify that it works correctly before continuing with the rest of the problem.
Plot[functionMaker[1][x], {x, 0, 10}]
Animate[Plot[functionMaker[n][x], {x, 0, 10}], {n, 1, 5, 0.1}]


You may also condsider using ParametricNDSolve for this kind of problem. 
POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract