Confused writing a function and its result - depending on reevaluation of the function
Subject: Confused writing a function and its result - depending on reevaluation of the function
From: Stavros Macrakis
Date: Wed, 27 Apr 2011 11:04:23 -0400
As Jaime has said, it is generally better to work with *expressions* than
with *named functions* in Maxima.
But I just wanted to clarify the semantics of some of the constructs you
used in your code:
f(x):=...
>
Function definitions are global, not local. To make them local, you can use
local(f) in the function block, but I would recommend you not define a
function at all.
...:=''f,
>
The '' operator takes effect when your function is READ into the system, NOT
when it is executed, so this will not have the expected effect.
> N: makelist([xi:float(ev(x,l[i])), float(f(xi))], i , 1, length(l)),
>
I would recommend subst(l[i],x) rather than ev.
> return (erg)
>
The value of the last expression in a function is the returned value, so you
don't need return here.
-s
>
> I call it in this way:
>
> f: (x-3)*(x+4)*(x-7)/20;
> ergebnis: kurvendiskussion(f)$
> disp("","Aufgabe",ergebnis)$
>
> When I call it first I'll get:
>
> "Aufgabe"
>
> matrix(["Funktion","Ableitung","Nullstellen","Extremwerte","Wendepunkt"],[((
>
> x-7)*(x-3)*(x+4))/20,matrix([(3*x^2-12*x-19)/20],[(6*x-12)/20],[3/10],[0]),m
>
> atrix([[-4.0,0.05*(x^3-6.0*x^2-19.0*x+84.0)]],[[3.0,0.05*(x^3-6.0*x^2-19.0*x
> +84.0)]],[[7.0,0.05*(x^3-6.0*x^2-19.0*x+84.0)]]),matrix([[-1.2145502269
> 26804
>
> ,0.05*(x^3-6.0*x^2-19.0*x+84.0)]],[[5.214550226926804,0.05*(x^3-6.0*x^2-19.0
> *x+84.0)]]),matrix([[2.0,0.05*(x^3-6.0*x^2-19.0*x+84.0)]])])
>
> Which I do not really want as I want the real values. Now I evaluate the
> above function definition again and rerun the previous call. Now I get:
> "Aufgabe"
>
> matrix(["Funktion","Ableitung","Nullstellen","Extremwerte","Wendepunkt"],[((
>
> x-7)*(x-3)*(x+4))/20,matrix([((x-3)*(x+4))/20+((x-7)*(x+4))/20+((x-7)*(x-3))
>
> /20],[(x+4)/10+(x-3)/10+(x-7)/10],[3/10],[0]),matrix([[-4.0,0.0]],[[3.0,0.0]
> ],[[7.0,0.0]]),matrix([[-1.2145502269
> 26804,4.821701928786462]],[[5.214550226
> 926804,-1.821701928786462]]),matrix([[2.0,1.5]])])
> That's actually what I like...
>
> Any idea what I do wrong?
>
> Attached also a file in wxm Format which contains the function definitions.
>
> Thanks for help on this.
>
> BTW: Does anyone know a good description about Maxima programming?
>
> Klemens
>
>
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>