On Mar 8, 5:14 am, compound eye <compound...@gmail.com> wrote: > hello > > I expected the code below to plot a diagonal line from 0,0 to 2,2 then > a horizontal line from 2,2 > > but instead it plots a horizontal line starting at 0,2 > > x = var('x') > > def splitTest(n): > > if n < 2: > return n > else: > return 2 > > plot(splitTest(x),0,4) > > splitTest(1) returns 1 as expected > > can anyone explain this to me?
This question comes up pretty frequently here. I think the problem is that when you say "plot(splitTest(x), 0, 4)", first splitTest(x) is evaluated, which means that bool(x<2) is evaluated, and this returns False (try it). Thus splitTest(x) returns 2. The difference with plot(splitTest, 0, 4) is that it passes the *function* splitTest to plot, rather than the value (as best it can determine) of splitTest(x) in what you were doing. For your 4-variable case, try something like def oneinput(x): return fourInputFunction(x, 1, 2, 3) plot(oneinput, 0, 4) --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---