From: Jaime V. <vi...@fe...> - 2024-04-06 20:38:34
|
On 06/04/24 19:30, Jaime Villate via Maxima-discuss wrote: > 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, f,10,0,1)]], [x,0,1], nolegend); Please keep in mind that this is a hack for this case but should be used with caution. If I now write: g(x):=sin(x)$ plot2d([g,[discrete, stair(g,10,0,%pi)]], [x,0,%pi], nolegend); the plot shows the function sin(x) but the stair for function f(x):=1/(1+x), because f is not really an input parameter for function stair, but it has been "hard-coded" into that function. It is usually easier to deal with expressions than with functions, which is the approach used in the command staircase in share/dynamics/dynamics.mac. How about f(x):=sin(x)$ plot2d([f,[discrete, stair(f,10,0,%pi)]], [x,0,%pi], nolegend); it shows the correct stair corresponding to sin(x) but that stair is below the function, where the function is increasing, and above the function once it starts decreasing, which is probably not what we would want. Regards, Jaime |