First time here? Check out the FAQ!

Ask Your Question
1

Evaluating the derivative of piecewise functions

asked 8 years ago

franpena gravatar image

Hi,

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()
-0.416146836547142

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()
0.540302305868140

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 8 years ago

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

diff(f.expression_at(1))(1).n()
Preview: (hide)
link

Comments

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 ( 8 years ago )

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

Stats

Asked: 8 years ago

Seen: 618 times

Last updated: Feb 05 '17