Confused writing a function and its result - depending on reevaluation of the function



On Tue, 2011-04-26 at 20:27 +0200, Dr. Klemens Waldh?r wrote:
> 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:
...
> 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:
...
> That's actually what I like...

Hi,
in fact, if you defined f:... first, before defining
kurnvendiskussion(), you would also get the result you want.
Your problem here is that you think you are defining a local function
f() which will not interfere with the global f, but doing that is very
tricky and cannot be done as you tried.
I recommend that you stick to expressions and do not use functions
(expressions will in fact be local as you expect them to be):

kurvendiskussion(func) :=
block(
[ab1,ab2,ab3,ab4,N,E,W,l,erg,abl,xi],
ab1:ratsimp(diff(func,x)),
ab1:ratsimp(diff(func,x)),
ab2:ratsimp(diff(func,x,2)),
ab3:ratsimp(diff(func,x,3)),
ab4:ratsimp(diff(func,x,4)),
l:realroots(func=0),
N: makelist(float(ev([x,func],l[i])), i , 1, length(l)),
l:realroots(ab1=0),
E: makelist(float(ev([x,func],l[i])), i , 1, length(l)),
l:realroots(ab2=0),
W: makelist(float(ev([x,func],l[i])), i , 1, length(l)),
abl: [ab1,ab2,ab3,ab4],
erg:
matrix(["Funktion","Ableitung","Nullstellen","Extremwerte","Wendepunkt"],
[func, transpose(abl), transpose(N),transpose(E),transpose(W)]),
return (erg)
)$


Cheers,
Jaime