Question: How to handle piecewise defined matrix valued functions

Hi,

I have some matrix valued functions that that I can only define piecewise. Unfortunately I have some problems to manipulate those functions. Piecewise sees to do the job for  scalar valued functions. There I can easily differentiale and add results. For Matrix valued functions however, those features seem to not be availible.
 

I can work around these limitations by manually applying all operations to the operands of the piecewise function. Like I show here:


 

restart:

# a piecewise function

p1:=piecewise(a(t)^2=0,<cos(a(t))^2+sin(a(t))^2,0>,<1,1/a(t)>)

p1 := piecewise(a(t)^2 = 0, Vector(2, {(1) = cos(a(t))^2+sin(a(t))^2, (2) = 0}), Vector(2, {(1) = 1, (2) = 1/a(t)}))

(1)

# differentiation does not work

diff(p1,t)

diff(piecewise(a(t)^2 = 0, Vector(2, {(1) = cos(a(t))^2+sin(a(t))^2, (2) = 0}), Vector(2, {(1) = 1, (2) = 1/a(t)})), t)

(2)

# selecting individual entries does not work

r:=p1(1)+1

r := (piecewise(a(t)^2 = 0, Vector(2, {(1) = cos(a(t))^2+sin(a(t))^2, (2) = 0}), Vector(2, {(1) = 1, (2) = 1/a(t)})))(1)+1

(3)

# strange simplification behaviour

simplify(p1)

piecewise(t = RootOf(a(_Z)), _z1(RootOf(a(_Z))), Vector(2, {(1) = 1, (2) = 1/a(t)}))

(4)

# current workaround, define new piecewise function by using op

r:=piecewise(op(1,p1),op(2,p1)(1)+1,op(3,p1)(1)+1)

r := piecewise(a(t)^2 = 0, cos(a(t))^2+sin(a(t))^2+1, 2)

(5)

 


 

Download Scratch.mw

 

I think my workaround is very cumbersome and error prone. Is there a better way to tackle this probem? Or should I try to overload all needed operations, and is this even possible?

Thanks for all suggestions!

Honigmelone

Please Wait...