animate & stats distribution (23.9.98)

Richard Gonzalez

I’m trying to prepare a demo for class. I want to animate some distributions as a function of degrees of freedom and am having problem (most likely I’m misunderstanding something about evaluation).

Here is a static plot of an example of what I want to do:

display({plot(statevalf[pdf, studentst[25]](x), 
plot(statevalf[pdf, studentst[5]](x), x=-6..6,colour=blue), 
plot(statevalf[pdf, studentst[2]](x), 
x=-6..6,colour=black),plot(statevalf[pdf, studentst[1000]](x), 

I thought the following would be a way to animate the plot as a function of the parameter of ”studentst” but all I get are axes

animate(statevalf[pdf, studentst[t]](x), x=-3..3,t=5..1000);

this example works fine

animate( sin(x*t),x=-10..10,t=1..2);

I don’t understand why the latter animate works and the former doesn’t.

Robert Israel (24.9.98)

Premature evaluation strikes again! The animate function, like most Maple functions, evaluates its arguments first. The result is that statevalf[pdf, studentst[t]](x) gets called with a symbolic t, and statevalf doesn’t like that: it insists on the parameter of studentst being numerical. The simplest way to get around it, I think, is to use display(..., insequence=true) instead of animate. Something like this:

> display([seq(plot(statevalf[pdf, studentst[5+100*j]](x), x=-3..3), 
                       j=0..10)], insequence=true);

This works because seq is not like most Maple functions: it only evaluates the first argument after substituting a numerical value for the loop variable j.

Bill Bauldry (24.9.98)

It’s an evaluation problem. My favorite trick for evaluating animate works here, too. Try:

> with(plots): 
> clr := vector([blue,black,red,green]): 
> P := t -> 
  plot(statevalf[pdf, studentst[t]](x), x=-6..6, colour=clr[1+(t mod 4)]); 
> display([seq(P(5*t), t=1..10)], insequence=true);

Preben Alsholm (25.9.98)

The problem is that in studentst[t] the degree of freedom t has to be a positive integer. However, animate picks floats in the range you give for t. You could replace t with round(t), or you could instead create the frames first and then display them in sequence:

The second idea first:

L:=[seq(plot(statevalf[pdf, studentst[t]](x), 

The first remedy:

animate(statevalf[pdf, studentst[round(t)]](x), x=-3..3,t=1..1000);