On Saturday, April 23, 2016 at 11:29:07 AM UTC+2, Massimo D'Antoni wrote: > > I need to define a function like the following (the function cannot assume > negative values): > > y = 5 - 2x if f(x)>0 > 0 otherwise > > Hi, you cannot mix python syntax with building a symbolic expression when solving ... the root problem is, that expressions are "built up" and not evaluated, while python functions are evaluated from the inside.
Try: g(x) = heaviside(f(x)) * f(x) and about solve, why not just g(4)? > plots incorrectly in python world, it's functor is either the function itself or lambda, i.e. with def g(x): return f(x) if f(x)>0 else 0 try this: plot(lambda x : g(x), (x, -10, 10)) reason why your second plot attempt with a python function fails is, that it is evaluated when you write down g(x) and inside of it, bool(f(x) > 0) is False and hence always zero. Tricky, because two worlds collide … -- h -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.