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



On 4/27/2011 3:15 AM, Jaime Villate wrote:
> On Wed, 2011-04-27 at 11:12 +0100, Jaime Villate wrote:
>> 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)),
....

I think you will find something like this works, and is much shorter.

kurvendiskussion(func) :=
block([],
local(ab, N),
ab[0]:rat(func),
ab[i]:=diff(ab[i-1],x),

for i from 0 thru 2 do
   (l:realroots(ab[i]=0),
    N[i]: makelist(float(ev([x,func],l[j],j,1,length(l))),

matrix( [funktion, ableitung, nullstellen extremwerte, wendepunkt],
[func, transpose(makelist(ab[i],i,0,3)),  transpose(N[0]), 
transpose(N[1]), transpose(N[2])])

)