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



The function f isn't local to the function kurvendiskussion--I think this causes 
the problem you observed. One way to fix this is to use buildq to define f to be a 
lambda form. Also, I eliminated your use of ev by mapping a lambda form over a
list. Finally, the return statement isn't needed, so I eliminated it.

Try something like:


kurvendiskussion(func) :=block([ab1,ab2,ab3,ab4,N,E,W,l,erg,abl,f,xi,x],
x : first(block([listdummyvars : false, listconstvars : false], listofvars(func))),
f : buildq([x,func], lambda([x], func)),
ab1:diff(f(x),x),
ab2:diff(f(x),x,2),
ab3:diff(f(x),x,3),
ab4:diff(f(x),x,4), 
l:realroots(f(x)=0),
N : map(lambda([s], [s, float(f(s))]), map('rhs,l)),
l:realroots(ab1=0),
E : map(lambda([s], [s, float(f(s))]), map('rhs,l)),
l:realroots(ab2=0),
W : map(lambda([s], [s, float(f(s))]), map('rhs,l)),
abl: [ab1,ab2,ab3,ab4],
matrix(["Funktion","Ableitung","Nullstellen","Extremwerte","Wendepunkt"],
[func, transpose(abl), transpose(N),transpose(E),transpose(W)]))$



--Barton

-----maxima-bounces at math.utexas.edu wrote: -----

>To:?<maxima at math.utexas.edu>
>From:?"Dr.?Klemens?Waldh?r"?<klemens.waldhoer at heartsome.de>
>Sent?by:?maxima-bounces at math.utexas.edu
>Date:?04/26/2011?01:27PM
>Subject:?[Maxima]?Confused?writing?a?function?and?its?result?-?depending
>on	reevaluation?of?the?function
>
>I?have?written?the?follwoing?function?which?basically?does?some?function
>discussion:
>
>kurvendiskussion(func)?:=
>block(
>[ab1,ab2,ab3,ab4,N,E,W,l,erg,abl,x,f,xi],
>f:?ratsimp(func),
>f(x):=''f,
>ab1:diff(f(x),x),
>ab2:diff(f(x),x,2),
>ab3:diff(f(x),x,3),
>ab4:diff(f(x),x,4),
>l:realroots(f(x)=0),
>N:?makelist([xi:float(ev(x,l[i])),?float(f(xi))],?i?,?1,?length(l)),
>l:realroots(ab1=0),
>E:?makelist([xi:float(ev(x,l[i])),?float(f(xi))],?i?,?1,?length(l)),
>l:realroots(ab2=0),
>W:?makelist([xi:float(ev(x,l[i])),?float(f(xi))],?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)
>)$
>
>
>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.2145502269268
>04
>,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.214550226926804,4.821701928786462]],[[5.2145502
>26
>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
[attachment "kurvendiskussion.wxm" removed by Barton Willis/MATH/UNK/UNEBR]