Maxima-区分分段函数 [英] Maxima - differentiating a piecewise function

查看:153
本文介绍了Maxima-区分分段函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您有一个由间隔定义的函数,例如

Suppose you have a function defined by intervals, such as

f(x):=block(if x<0 then x^2 else x^3);

当我们将其与

diff(f(x),x);

我们得到

d/dx (if x<0 then x^2 else x^3)

我想得到

(if x<0 then 2*x else 3*x^2)

有没有办法获得这样的结果?

Is there a way to obtain such result?

推荐答案

这是对"if"表达式使用简化规则的另一种方法.此处未解决的部分是检测不连续性并为这些位置生成增量函数.如果要忽略它们,则可以定义FOO返回0.这部分在这里尚未解决.如果有兴趣,我可以尝试一下.

Here's a different approach using a simplification rule for "if" expressions. The unsolved part here is to detect discontinuities and generate delta functions for those locations. If you want to ignore those, you can define FOO to return 0. Note that I didn't attempt to implement the function discontinuities; that part is unsolved here. I can give it a try if there is interest.

(%i1) display2d : false $
(%i2) matchdeclare ([aa, bb, cc], all, xx, symbolp) $
(%i3) 'diff (if aa then bb else cc, xx) $
(%i4) tellsimpafter (''%, apply ("if", [aa, diff (bb, xx), true, diff (cc, xx)]) + FOO (aa, bb, cc, xx)) $
(%i5) FOO (a, b, c, x) := 'lsum ((ev (c, x = d) - ev (b, x = d)) * delta (d, x), d, discontinuities (a, x)) $
(%i6) diff (if x > 0 then x^2 else x^3, x);
(%o6) (if x > 0 then 2*x else 3*x^2)+'lsum((d^3-d^2)*delta(d,x),d,
                                           discontinuities(x > 0,x))

这篇关于Maxima-区分分段函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆