From: Eduardo O. <edu...@gm...> - 2024-10-10 04:53:20
|
On Wed, 9 Oct 2024 at 21:48, Robert Dodier <rob...@gm...> wrote: > On Wed, Oct 9, 2024 at 2:33 PM Eduardo Ochs <edu...@gm...> wrote: > > > P(t) := if t <= 6 then [t,4] else [6,10-t]; > > draw2d(explicit(P(t)[1], t,0,10), > > explicit(P(t)[2], t,0,10)); > > draw2d(parametric(P(t)[1], P(t)[2], t,0,10)); > > > > The first three "draw2d"s work perfectly, but the last one > > yields this error: > > > > draw2d (parametric): non defined variable > > This is due to a bug in the way that parametric verifies that the > first two arguments are functions of the parameter t alone. > `listofvars` is called, but listofvars(foo(x)[1]) returns [foo(x)[1]], > not [x] as one might hope. > > I guess this could be interpreted as a bug in listofvars. It is > supposed to return [x[1]] for listofvars(x[1] + 2), for example, but > maybe if the expression looks like listofvars(foo(x)[1] + 2) it should > return [x]. > > As a workaround, one could say something like > > P1(t) := if t <= 6 then t else 6; > P2(t) := if t <= 6 then 4 else 10 - t; > draw2d (parametric (P1(t), P2(t), t, 0, 10)); > > I know that's less elegant in a way. > > Robert Perfect, thanks! Here is a way to write that workaround that I find more readable: P(t) := if t <= 6 then [t,4] else [6,10-t]; /* redefine as: */ P(t) := [if t <= 6 then t else 6, /* x */ if t <= 6 then 4 else 10-t]; /* y */ draw2d(xrange=[-1,8], yrange=[-1,8], parametric(P(t)[1],P(t)[2], t,0,10)); Solved! Cheers =), Eduardo Ochs |