Ask Your Question

Substitute piecewise function variable

asked 2017-03-24 20:39:26 +0200

jrojasqu gravatar image

I have the following piecewise function:

phi   = piecewise([([-1,1], (1-abs(x))*(1-abs(x))*(1+2*abs(x)))]);
phi   = phi.extension(0);

It appears to be a valid function since I can obtain/plot its values for any 'x'. But whenever I try to substitute the variable, it does not work. For example,


but if I declare another variable 'h' and try to input that variable into the piecewise function, it does not appear to work:

TypeError: self must be a numeric expression

At first I thought that 'h' was not a 'numeric' or 'real' value, but when I test it, it is a real value:


How can I overcome this? How can I successfully operate a variable substitution in my piecewise function?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-03-24 23:41:35 +0200

If you check the type of h with type(h), it comes back as

<type 'sage.symbolic.expression.Expression'>

which is not numeric but symbolic. You can convert it to a numeric value with n(h) or h.n() and then the substitution will give zero as expected.

edit flag offensive delete link more


@paulmasson Thanks, it worked; and I would at least vote your answer but I lack the minimum 10 points to do so...

jrojasqu gravatar imagejrojasqu ( 2017-03-28 01:08:35 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-03-24 20:39:26 +0200

Seen: 684 times

Last updated: Mar 24 '17