如何从包含特定变量MAPLE的符号表达式中获得部分表达式? [英] How to get partial expression from symbolic expression containing specific variable MAPLE?

查看:292
本文介绍了如何从包含特定变量MAPLE的符号表达式中获得部分表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下的符号表达式

I have a symbolic expressions as below

y1 = (1/a)-(b/a^2)+x*a*b-x/b
y2 = a*b+a*x+b*sqrt(x)

现在我需要获取具有特定术语的部分表达式.像

now I need to get the partial expressions which have specific term. Like

xFunction(y1, x) # should return x*a*b-x/b
xFunction(y2,x)  # should return a*x+b*sqrt(x)

任何建议或想法都非常有用 谢谢

any suggestions or idea are very healpful Thank you

推荐答案

restart;

y1 := (1/a)-(b/a^2)+x*a*b-x/b:
y2 := a*b+a*x+b*sqrt(x):

K := (ee,x) -> `if`(ee::`+`,select(depends,ee,x),ee):

K( y1, x );

                     x
             x a b - -
                     b

K( y2, x );

                     (1/2)
            a x + b x     

#
# Leave alone an expression which is not a sum of terms.
#
K( sin(x+4)*x^3, x );

                         3
             sin(x + 4) x 

#
# Don't select subterms in which `x` is a just dummy name.
#
K( x^3 + sin(x) + Int(sqrt(x), x=a..b), x );

               3         
              x  + sin(x)

[已编辑]

y1 := (1/a)-(b/a^2)+x*a*b-x/b;

                      1   b            x
                y1 := - - -- + x a b - -
                      a    2           b
                          a             

op(3,y1);

                         x a b

depends(op(3,y1), x);

                          true

select命令将其第一个参数映射到 第二个参数的所有操作数.

The select command maps its first argument over all the operands of its second argument.

select( s->depends(s,x), y1 );

                               x
                       x a b - -
                               b

更简洁的语法,其中select映射其第一个 参数depends在其第二个操作数上 参数,并将其第三个参数作为附加参数传递 选项(选择器).

A more terse syntax, where select maps its first argument depends over the operands of its second argument, and passes its third argument as additional options (to the selector).

select( depends, y1, x );

                               x
                       x a b - -
                               b

现在创建一个过程来完成它.使用条件 测试,以便它返回第一个参数本身 只要不是条件之和.

Now create a procedure to do it. Use a conditional test, so that it returns the first argument itself whenever that is not a sum of terms.

K1 := proc(ee, x)
  if type(ee,`+`) then
    select( depends, ee, x );
  else
    # leave it alone
    ee;
  end if;
end proc:

K1( y1, x);

                               x
                       x a b - -
                               b

对该类型检查使用更简洁的语法.

Using a more terse syntax for that type-check.

K2 := proc(ee, x)
  if ee::`+` then
    select( depends, ee, x );
  else
    # leave it alone
    ee;
  end if;
end proc:

K2( y1, x);

                               x
                       x a b - -
                               b

为if..then..end if使用更简洁的语法. 这是if的所谓运算符形式.这个单词 if在名称引号内,以将其与 if ... then ...中结束时的语言关键字.

Using a more terse syntax for that if..then..end if. This is the so-called operator form of if. The word if is within name-quotes, to distinguish it from the language keyword within an if...then...end if .

K3 := proc(ee, x)
  `if`( ee::`+` , select( depends, ee, x ), x );
end proc:

K3( y1, x);

                               x
                       x a b - -
                               b

由于过程K3的主体只有一条语句,因此 我们可以使用所谓的运算符使其更简洁 表格.

Since the body of the procedure K3 has only a single statement then we can make it more terse, using the so-called operator form.

K4 := (ee, x) -> `if`( ee::`+` , select( depends, ee, x ), x ):

K4( y1, x);

                               x
                       x a b - -
                               b

这篇关于如何从包含特定变量MAPLE的符号表达式中获得部分表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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