From: Jaime V. <vi...@fe...> - 2024-04-06 18:39:35
|
On 06/04/24 19:30, Jaime Villate via Maxima-discuss wrote: > > > On 06/04/24 19:20, Robert Dodier wrote: >> I traced E and g and I think what's happening is that 'if x = b then >> ... ' fails if x is a float and b is an integer, but x is equal to >> float(b). Then the loop runs all the way through and eventually yields >> 'done'. That nonnumeric value causes plot2d to complain. >> >> There have been various changes to plot2d over the last couple of >> years, and it seems likely OP is running a version which refuses to >> plot if even one value is nonnumeric. The current version just filters >> out nonnumeric values, which is, I think, as it should be (and has >> been at times in the past). > > That makes sense. > > In any case, the "staircase" that Pierre wants to plot is definitely > not a function but a polygonal line, so I suggest to use the following > approach (which is what staircase does in my dynamics package): > > stair(f,n,a,b):=block > ([r:[[a,f(a)]], s:(b-a)/n, y: f(a)], > for x:a+s thru b step s do > (r: append(r, [[x, y], [x, f(x)]]), y: f(x)), > r)$ > f(x):=1/(1+x)$ > plot2d([f,[discrete, stair(1/(1+x),10,0,1)]], [x,0,1], nolegend); That's correct but I mean to say: plot2d ([f, [discrete, stair (f, 10, 0, 1)]], [x, 0, 1], nolegend); and if Pierre is using and old version of Maxima, he will probably need [legend,false] instead of nolegend. Jaime |