plot array of functions



On 02/03/2012 11:47 AM, Pierpaolo Garofalo wrote:
> I am a new maxima user so if my question has been already answered elsewhere, please bear with me. I would be grateful if someone could provide
>
> a link to some explanation...  I googled around for hours before posting here.
>
>
> I am trying to plot a star of lines and for this purpose I am trying to rely on a vector of functions. So far I have made my way to this point:
>
> array(Y,9);
>
> for i:0 thru 9 do block(Y[i](x):=i*x, display(Y[i]));
>
> plot2d([Y(x)],[x,-5,5]);
>
> plot2d: expression evaluates to non-numeric value everywhere in plotting range.
> plot2d: nothing to plot.
> (%o103) false
Hi,
welcome to this group. Feel free to ask whenever you get stuck. Eric has 
already
told you the answer, but since you are new user I'd like to point out 
why your attempt
failed.

First of all, you should avoid using arrays, at least until you're more 
familiar with Maxima.
You could have created a list rather than an array by simply writing the 
"for" command
right away:
   for i:0 thru 9 do (Y[i](x) := i*x, display (Y[i]));
notice also that you do not need block in this case, since you are not 
defining any local
variables.

After you have defined those 10 functions, Y(x) will not refer to the 
list of those 10 functions
but rather to another different function which you have not defined yet. 
That's why plot2d
complaints that Y(x) evaluates to a non-numeric value, because in fact 
it cannot be evaluated
since it has not been defined.

To get a list with the ten functions you defined, you would have to write:
   [Y[0](x), Y[1](x), Y[2](x), Y[3](x), Y[4](x), Y[5](x), Y[6](x), 
Y[7](x), Y[8](x), Y[9](x)]

or simply,
   makelist (Y[i](x), i, 0, 9)

which will give you the same result.

But in Maxima it makes life easier to represent mathematical functions 
by expressions rather
than defining procedures with an input variable. Namely, get used to:

f: x^2 + 2;
at (f, x=5);

instead of:

f(x) := x^2 + 2;
f(5);

Regards,
Jaime