Question: How to get procedure to handle f or f(x,y)

I have a procedure to truncate algebraic equations. Found the basic answer hrere. I would like to make it handle equations and functions i.e f:=a x^2 +b y... and f(x,y):=c x y^2.... I can make it handle the first type but not the second.

restart

``

NULL

NULL

Trunc := proc (eq, odr := 2, v::list := [x, y, z]) local a, b, q; description " Truncates an algebraic equation to required degree"; a := eq; b := v; map(select, proc (q) options operator, arrow; evalb(degree(q, b) <= odr) end proc, a) end proc

proc (eq, odr := 2, v::list := [x, y, z]) local a, b, q; description " Truncates an algebraic equation to required degree"; a := eq; b := v; map(select, proc (q) options operator, arrow; evalb(degree(q, b) <= odr) end proc, a) end proc

(1)

"E1(x,y,z):=2+3 x-y+5 x^(2)y+4 x y+x y^(3)+3 a^(2)+z+z^(2)"

proc (x, y, z) options operator, arrow, function_assign; 2+3*x-y+5*x^2*y+4*y*x+x*y^3+3*a^2+z+z^2 end proc

(2)

Trunc(E1, 2, [x, y, z])

E1

(3)

``

E2 := E1(x, y, z)

x*y^3+5*x^2*y+3*a^2+4*x*y+z^2+3*x-y+z+2

(4)

Trunc(E2, 1, [x, y])

3*a^2+z^2+3*x-y+z+2

(5)

Trunc(E2, 1, [x, y, z])

3*a^2+3*x-y+z+2

(6)

``whattype(E1(x, y, z))

`+`

(7)

whattype(E2)

`+`

(8)

``


 

Download Truncate.mw

Please Wait...