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
this example works fine
I don’t understand why the latter animate works and the former doesn’t.
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:
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.
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);
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), x=-3..3),t=[2,5,25,100,500,1000])]: display(L,insequence=true);
The first remedy: