我试图解决 Maxima 中的分段函数,但没有返回函数的解决方案:
piecewiseExample(x) := if (x < 5) then x*2 else x/2;
solve([piecewiseExample(x) = 4], [x]);
//result: [(if x<5 then 2*x else x/2)=4]
Maxima 是否有可能获得像这样的方程的解?
在简单的情况下,你可以解决每一个分支无处不在和过滤解决方案:
solve_and_filter(eq, var, p):= block([so: solve(eq, var), prederror: true],
sublist(so, lambda([c], p(rhs(c))))) $
pw_solve(pw, var):= map(lambda([L],
solve_and_filter(first(L), var, second(L))), pw) $
/* represent piecewise equation as a list of equation-predicate pairs
[ [eq1, pred1], [eq2, pred2], ... ] */
pw: [ [x*2 = 4, lambda([x], x< 5)],
[x/2 = 4, lambda([x], x>=5)]] $
/* solve every `eq' and filter solutions using `pred' */
pw_solve(pw, x);

一种选择是使用数值方法:
(%i1) f(x) := if (x < 5) then x*2 else x/2;
x
(%o1) f(x) := if x < 5 then x 2 else -
2
(%i9) find_root(f(x)-4,x,-1000,1000);
(%o9) 8.0
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(15条)