Ask Your Question

Evaluating the derivative of piecewise functions

asked 2017-02-04 19:43:29 +0200

franpena gravatar image


In Sage 7.5 you can numerically evaluate the derivative of a regular symbolic expression using:

sage: h(x) = sin(x)
sage: diff(h)(2).n()

Old Piecewise functions could be treated in the same way:

sage: g = Piecewise([([0,2], sin(x)), ((2,3), cos(x))])
... DeprecationWarning ...
sage: diff(g)(1).n()

However, new piecewise functions don't:

sage: f = piecewise([([0,2], sin(x)), ((2,3), cos(x))])
sage: diff(f)(1).n()
... Error ...

Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-02-05 21:25:05 +0200

The new piecewise is unfortunately not very user friendly. Here's one workaround:

edit flag offensive delete link more


Thank you @paulmasson. So that means that piecewise cannot operate as similar as Piecewise does with symbolic expressions. In my opinion this is a drawback.

franpena gravatar imagefranpena ( 2017-02-10 17:20:56 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-02-04 19:43:29 +0200

Seen: 554 times

Last updated: Feb 05 '17