8
$\begingroup$
Animate[Plot[2 x a - a^2, {x, -2, 2}], {a, -2, 2}, AnimationRunning -> False]

During run I need the output to display two things

  1. Leave a trace of the straight line tangent on a default increment of animation parameter a.
  2. Prevent the axes from quivering (not steady) while axes are scaled for each plot.

By specifying fixed range/domain limits can I effectively fix the 2nd problems?

EDIT1:

a = 1; plt1 = Plot[2 x a - a^2, {x, -2, 2}];
a = .5; plt2 = Plot[2 x a - a^2, {x, -2, 2}];
a = -.5; plt3 = Plot[2 x a - a^2, {x, -2, 2}];
a = -1; plt4 = Plot[2 x a - a^2, {x, -2, 2}];
Show[{plt1, plt2, plt3, plt4}]

EDIT2:

BTW, it is solution of Clairaut's Differential equation

$$ y = 2p-p^2,\, p= \frac{dy}{dx}, $$

with singular solution

$$y=x^2 $$

which can be seen here.

$\endgroup$
  • $\begingroup$ Ad 2) just add PlotRange -> {-10, 5} (or any plot range that looks appealing to you) in the Plot. $\endgroup$ – corey979 Nov 11 '16 at 22:19
  • $\begingroup$ Thanks, Some of fleeting lines 1) need also to be captured. $\endgroup$ – Narasimham Nov 11 '16 at 22:23
  • 1
    $\begingroup$ Do you know how to make a static plot showing the set of tangents you want to see in the animation? If you do, then it's not hard to animate what you want. If not, you should work on the static plot first. When you done that come back with any questions about converted it an animation. $\endgroup$ – m_goldberg Nov 11 '16 at 22:26
  • $\begingroup$ What do you mean by "leaving behind a trace"? Is this something you to do or is it something you want to suppress? You need to be clearer. $\endgroup$ – m_goldberg Nov 11 '16 at 22:33
  • $\begingroup$ Yes. I choose a parameter value, plot to that value calling it plot1, likewise choose a second parameter labelled plot2 .... and Show them all. kind of nasty. $\endgroup$ – Narasimham Nov 11 '16 at 22:33
12
$\begingroup$
plots = Table[
   Plot[2 x a - a^2, {x, -2, 2}, Filling -> Axis, 
    PlotRange -> {-5, 3}], {a, -1, 1, 0.1}];

frames = FoldList[Show, First @ plots, Rest @ plots];
  (* or simply *)
frames = FoldList[Show, plots] (* thanks: Simon Woods *)

ListAnimate[frames, AnimationRate -> 2]

enter image description here


Exported with

Export["plot.gif", frames, "DisplayDurations" -> 1/2]
| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ In recent versions you can use frames = FoldList[Show, plots] $\endgroup$ – Simon Woods Nov 12 '16 at 8:30
16
$\begingroup$

This approach is slightly more complicated than corey979's but has the advantage that number of ghost lines is independent from the number of a you want to use (in other words, the animation below is "continuous", not step by step).

aMax = 4; (* max value of a *)
n = 30; (* number of ghost lines *)
f[x_, a_] = 2 x a - a^2;
lines = Table[Line[{{-aMax, f[-aMax, a]}, {aMax, f[aMax, a]}}], {a, 
    Subdivide[-aMax, aMax, n]}];
showLines[a_] := Block[{},
  pos = Position[Subdivide[-aMax, aMax, n], _?(# < a &)];
  If[Length@pos > 0, Graphics[{Lighter[Blue, .4], lines[[;; Last@Last@pos]]}], 
   Graphics[]]]
list = Table[ Show[Plot[2 x a - a^2, {x, -aMax, aMax}, PlotRange -> {{-3, 3}, {-10, 7}}, 
     PlotStyle -> Darker[Blue, .5]], showLines[a], 
    Frame -> True], {a, -aMax, aMax, 0.1}];

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Exporting shown @corey979 $\endgroup$ – Narasimham Nov 11 '16 at 23:15
  • $\begingroup$ @Narasimham I know this but I wanted to keep the Manipulate frame :) $\endgroup$ – anderstood Nov 11 '16 at 23:16
  • $\begingroup$ See here, although - works for .avi, doesn't work for .gif. $\endgroup$ – corey979 Nov 11 '16 at 23:30
  • $\begingroup$ @corey979 Yes I've seen this, but when converting the avi to gif rendered strange colors... Nevermind, I exported without the frame :) $\endgroup$ – anderstood Nov 11 '16 at 23:35
8
$\begingroup$

My bid for your consideration. First I would simplify the Plot to a single Line segment, then abstract this to a function:

(* s = start; i = increment *)

fn[s_, i_][f_] := Line @ Table[{{-2, -4 a - a^2}, {2, 4 a - a^2}}, {a, s, f, i}]

From there I can animate smoothly as follows:

Animate[
  Graphics[{{LightGray, fn[-2, 0.2][a]}, fn[a, 1][a]}
   , PlotRange -> {-5, 3}
   , AspectRatio -> 1/GoldenRatio
   , Axes -> True
  ]
  , {a, -2, 2}
  , AnimationRate -> 1
  , RefreshRate -> 60
  , DisplayAllSteps -> True
]

Animation:

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Small detail: for the animation, I changed the order in Graphics so that the main line is on top. $\endgroup$ – anderstood Nov 12 '16 at 20:47
  • $\begingroup$ @anderstood Thanks for the .GIF, and the note on order. I'll correct that in the code. $\endgroup$ – Mr.Wizard Nov 13 '16 at 0:11
  • 1
    $\begingroup$ I'm too lazy to write an answer, so: InfiniteLine[{0, -a^2}, {1, 2 a}] works well for depicting the lines, and it is easy to see how it was derived from the original equation of the line. $\endgroup$ – J. M.'s technical difficulties Dec 9 '16 at 22:16
  • $\begingroup$ @J.M. Thanks for the suggestion. It's good to see you posting again, by the way. :-) $\endgroup$ – Mr.Wizard Dec 11 '16 at 13:47
  • $\begingroup$ Yeah, it's great to be back; I was sick for most of my hiatus, so being able to post here again is nice. $\endgroup$ – J. M.'s technical difficulties Dec 11 '16 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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