Calling ev() during function definition



Dan <vi5u0-maxima at yahoo.co.uk> writes:
> Imagine I do something like (a more complicated version of) this
>
> load(draw) ;
>
> f(x) := 4*x^5 ;
> g(x) := 3*x^4 ;
>
> h(x) := ev(f(x)/g(x)) ;
>
> draw2d(explicit(h(x),x,0,7)) ;
>
> If I've understood correctly, the ev() is called separately for each
> specific numerical value of x during the draw2d().  A lot of
> CPU time could be saved by instead calling the ev()
> once and for all at the time h(x) is defined.  Is this possible,
> please?

I presume that you want to use the ev() call to simplify the
polynomials. Have you considered using a different function like
ratsimp()?

Anyway, the problem for you is that := doesn't evaluate its RHS by
default. To force it to do so, you can use the ''( <blah> )
construction. See the definition of h3 below.

Rupert


(%i1) f(x) := 4*x^5;
                                            5
(%o1)                            f(x) := 4 x
(%i2) g(x) := 3*x^4;
                                            4
(%o2)                            g(x) := 3 x
(%i3) h1(x) := ev(f(x)/g(x));
                                           f(x)
(%o3)                          h1(x) := ev(----)
                                           g(x)
(%i4) h1(3);
(%o4)                                  4
(%i5) h2(x) := f(x)/g(x);
                                          f(x)
(%o5)                            h2(x) := ----
                                          g(x)

<snip>

(%i7) h2(3);
(%o7)                                  4
(%i8) h3(x) := ''(ev(f(x)/g(x)));
                                          4 x
(%o8)                            h3(x) := ---
                                           3
(%i9) h3(3);
(%o9)                                  4
(%i10) 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 315 bytes
Desc: not available
URL: <http://www.math.utexas.edu/pipermail/maxima/attachments/20100922/be19816e/attachment.pgp>;