Ask Your Question

jrojasqu's profile - activity

2022-03-17 08:50:08 +0200 received badge  Famous Question (source)
2022-03-17 08:50:08 +0200 received badge  Notable Question (source)
2021-01-07 10:06:04 +0200 received badge  Notable Question (source)
2020-06-04 06:32:20 +0200 received badge  Popular Question (source)
2019-03-20 18:02:48 +0200 received badge  Popular Question (source)
2017-03-29 21:11:58 +0200 commented answer Integrate piecewise function with change of variable

@calc314 This is awesome... Had I thought about Heaviside for defining my piecewise functions, many of my problems in Sage would have been solved instantly... Thanks

2017-03-29 02:46:32 +0200 asked a question Integrate piecewise function with change of variable

I would like to integrate a piecewise defined function while operating a change of variable. I start by defining the function and another variable involved in the change of variable:

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

What I would like to do is integrate the function phi(x/h-1) between 0 and pi so I try it and results in

ValueError: substituting the piecewise variable must result in real number

So I then try to use another variable which I try to define to be 'real'


but it results in the same error... Now I try the "lambda" method since it worked when calling the plot function with the same change of variable; but fail again

integral(lambda t: phi(t/h-1),t,0,pi)
TypeError: unable to convert <function <lambda> at 0x16d71f140> to a symbolic expression

Now I try to use another integration method with definite_integral but get the same errors, only different for the "lambda" method

definite_integral(lambda x: phi(x/h-1),x,0,pi)
TypeError: cannot coerce arguments: no canonical coercion from <type 'function'> to Symbolic Ring

Is there any way around this? I really do not know what else to try...

2017-03-28 16:02:08 +0200 commented answer Substitute piecewise function variable

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

2017-03-25 00:26:50 +0200 received badge  Scholar (source)
2017-03-24 21:52:12 +0200 asked a question Substitute piecewise function variable

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?

2017-03-24 21:52:12 +0200 asked a question Create a band matrix with repeating and alternating values

I have 7 values: a, b, c, d, e, f and g

I would like to construct an m by n matrix in this way:

[ a b c d 0 0 0 0 . . . .]
[ b e f g 0 0 0 0 . . . .]
[ c f a b c d 0 0 . . . .]
[ d g b e f g 0 0 . . . .]
[ 0 0 c f a b c d 0 0 . .]
[ 0 0 d g b e f g 0 0 . .]
[ . . 0 0 c f a b c d . .]
[ . . 0 0 d g b e f g . .]

And so forth...

Therefore, the desired matrix is symmetrical. Values a and e alternate on the main diagonal; values b and f alternate on the 1st upper diagonal; values c and g alternate on the 2nd upper diagonal; values d and 0 alternate on the 3rd upper diagonal. I would like to be able to specify the matrix size with m by n parameters (even though the resulting matrix is non-square).

What would be an efficient way to construct this matrix?