#### 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:

with(stats);
display({plot(statevalf[pdf, studentst[25]](x),
x=-6..6,colour=red),
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),
x=-6..6,colour=green)});

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

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

this example works ﬁne

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 ﬁrst. 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 ﬁrst 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(stats):
> 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 ﬂoats in the range you give for t. You could replace t with round(t), or you could instead create the frames ﬁrst and then display them in sequence:

The second idea ﬁrst:

L:=[seq(plot(statevalf[pdf, studentst[t]](x),
x=-3..3),t=[2,5,25,100,500,1000])]:
display(L,insequence=true);

The ﬁrst remedy:

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