3

I've the following code:

ManToGif[man_, name_String, step_Integer] := 
  Export[name <> ".gif", 
   Import[Export[FileNameJoin[{NotebookDirectory[], "hoi2.avi"}], 
      man], "ImageList"][[1 ;; -1 ;; step]]];
hoi2 = Manipulate[Ud = x; Uin = 5; Rb = 10; c = 150*10^(-6);
  y[fin_] = 
   2*fin*(2*T*Ud - ((Ud)/(fin)) + ((Uin*Sin[2*Pi*fin*T])/(2*Pi*fin)) +
       c*Rb*(2*Ud - Uin)*(Exp[-((T)/(c*Rb))] - 1));
  Teqn[fin_] = 
   Abs[Uin*Sin[2*Pi*fin*T - (Pi/2)]] - 2*Ud == (Uin - 2*Ud)*
     Exp[-T/(c*Rb)];
  Tsol[fin_?NumericQ] := 
   FindRoot[Teqn[fin], {T, 1/(4*fin), 1/(2*fin)}]; 
  Show[ListPlot[
    Table[{fin, y[fin] /. Tsol[fin]}, {fin, 0.001, 1000, 0.01}]], 
   ListPlot[{{1000, 3.0214}, {500, 2.8021}, {250, 2.4941}, {125, 
      2.1516}, {62.5, 1.9251}, {0.01, 1.7622}}, 
    PlotStyle -> Red]], {x, 0, 1}]; ManToGif[hoi2, 
 FileNameJoin[{NotebookDirectory[], "hoi2"}], 1];

It creates two files, a .avi file and a .gif file. When I open the .gif file I get a black screen (so nothing is shown). What is the reason for that behaviour? What do you get when you run this code?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
asd
  • 143
  • 5
  • A Manipulate expression is a piece of code, not a sequence of images. Export has no automatic conversion from that code to images. – m_goldberg Jun 20 '18 at 01:13
  • 5
    @m_goldberg it actually does. Manipulate is smart enough to chunk itself and make a .gif file. Never made an AVI from one though – b3m2a1 Jun 20 '18 at 01:57
  • @b3m2a1. I am surprised. I admit I never tried to use Export that way. Thanks for putting me straight. – m_goldberg Jun 20 '18 at 02:22
  • @m_goldberg I was surprised too when I first saw it. I'd hazard that anything that has an Animator as part of its box structure can do that, too. – b3m2a1 Jun 20 '18 at 02:27
  • 1
    Related: https://mathematica.stackexchange.com/questions/4229/export-animation-of-a-manipulate-autorun-sequence/4231#4231 – Michael E2 Jun 20 '18 at 03:28
  • Please give the source for your ManToGif code, it was written by Vitaliy Kaurov if I recall correctly. – C. E. Oct 02 '18 at 04:27

1 Answers1

2

As of 11.1 Manipulate exports to GIF; In 11.2 Manipulate will also export to animated PNG. AVI doesn't support Manipulate just yet, but Manipulate and Table have a very similar syntax, for now one could simply change Manipulate to Table to generate a list of images and export as normal.

https://reference.wolfram.com/language/ref/format/GIF.html
https://reference.wolfram.com/language/ref/format/AVI.html

Edit:

Sorry I missed the last part of the question. I tried the code above, the Manipulate has a really hard time Dynamically updating and it mostly blows up with General::munfl: Exp[-166667.] is too small to represent as a normalized machine number; precision may be lost.

Since I can't get the Manipulate to work on its own, this is probably why your gifs are failing. The result of Table was however able to export to both formats.

GenericAccountName
  • 1,543
  • 9
  • 12